-
Notifications
You must be signed in to change notification settings - Fork 251
Add support for Amazon Q chat on remote 242+ #4825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
47706df
7f82602
1c06ff9
a2e4042
9f37025
4f4e3d2
9c49a0a
f46f20d
205251b
6257981
5ac379e
f94e290
f9fa72e
c1b9d17
baa8e8c
b7a8e2c
f5bb9bb
5f1a27a
fa2353e
e164b90
a878739
3a3671b
cc47655
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
|
||
package com.github.rli.cefschemeremotetest.toolWindow | ||
Check notice on line 3 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefLocalRequestHandler.kt
|
||
|
||
import org.cef.browser.CefBrowser | ||
import org.cef.browser.CefFrame | ||
import org.cef.callback.CefCallback | ||
import org.cef.handler.* | ||
import org.cef.misc.BoolRef | ||
import org.cef.network.CefRequest | ||
import java.net.URL | ||
|
||
/** | ||
* Handles local protocol-specific CEF resource requests for a defined `protocol` and `authority`. | ||
* | ||
* This class implements a mechanism to serve protocol-specific resources based on mappings provided | ||
* through the `addResource` function. Only requests matching the configured protocol and authority are processed, | ||
* while others are rejected. | ||
* | ||
* @param myProtocol The protocol to handle (e.g., "http", "file"). | ||
* @param myAuthority The authority of the requests (e.g., "localhost", "mydomain"). | ||
*/ | ||
open class JBCefLocalRequestHandler( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be used directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a straight copy from jetbrains so we should keep it slim to make it easy to copy over any changes later |
||
private val myProtocol: String, | ||
private val myAuthority: String | ||
) : CefRequestHandlerAdapter() { | ||
private val myResources: MutableMap<String, () -> CefResourceHandler?> = HashMap() | ||
|
||
private val REJECTING_RESOURCE_HANDLER: CefResourceHandler = object : CefResourceHandlerAdapter() { | ||
Check notice on line 29 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefLocalRequestHandler.kt
|
||
Check noticeCode scanning / QDJVMC Private property naming convention Note
Private property name REJECTING_RESOURCE_HANDLER should not contain underscores in the middle or the end
|
||
override fun processRequest(request: CefRequest, callback: CefCallback): Boolean { | ||
callback.cancel() | ||
return false | ||
} | ||
} | ||
|
||
private val RESOURCE_REQUEST_HANDLER = object : CefResourceRequestHandlerAdapter() { | ||
Check notice on line 36 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefLocalRequestHandler.kt
|
||
override fun getResourceHandler(browser: CefBrowser?, frame: CefFrame?, request: CefRequest): CefResourceHandler { | ||
val url = URL(request.url) | ||
url.protocol | ||
if (!url.protocol.equals(myProtocol) || !url.authority.equals(myAuthority)) { | ||
return REJECTING_RESOURCE_HANDLER | ||
} | ||
return try { | ||
val path = url.path.trim('/') | ||
myResources[path]?.let { it() } ?: REJECTING_RESOURCE_HANDLER | ||
} catch (e: RuntimeException) { | ||
println(e.message) | ||
REJECTING_RESOURCE_HANDLER | ||
} | ||
} | ||
} | ||
|
||
fun addResource(resourcePath: String, resourceProvider: () -> CefResourceHandler?) { | ||
val normalisedPath = resourcePath.trim('/') | ||
myResources[normalisedPath] = resourceProvider | ||
} | ||
|
||
fun createResource(resourcePath: String, resourceProvider: () -> CefResourceHandler?): String { | ||
Check warning on line 58 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefLocalRequestHandler.kt
|
||
val normalisedPath = resourcePath.trim('/') | ||
myResources[normalisedPath] = resourceProvider | ||
return "$myProtocol://$myAuthority/$normalisedPath" | ||
} | ||
|
||
override fun getResourceRequestHandler(browser: CefBrowser?, | ||
frame: CefFrame?, | ||
request: CefRequest?, | ||
isNavigation: Boolean, | ||
isDownload: Boolean, | ||
requestInitiator: String?, | ||
disableDefaultHandling: BoolRef?): CefResourceRequestHandler { | ||
return RESOURCE_REQUEST_HANDLER | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
|
||
package com.github.rli.cefschemeremotetest.toolWindow | ||
Check notice on line 3 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefStreamResourceHandler.kt
|
||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.util.Disposer | ||
import org.cef.callback.CefCallback | ||
import org.cef.handler.CefResourceHandler | ||
import org.cef.misc.IntRef | ||
import org.cef.misc.StringRef | ||
import org.cef.network.CefRequest | ||
import org.cef.network.CefResponse | ||
import java.io.IOException | ||
import java.io.InputStream | ||
|
||
/** | ||
* A handler for managing custom resource requests in JCEF. | ||
* This class implements the `CefResourceHandler` interface, enabling the customization of resource | ||
* loading from a provided input stream. It supports setting MIME types and headers for responses | ||
* and ensures proper disposal of resources. | ||
* | ||
* @param myStream The input stream from which the resource will be read. | ||
* @param myMimeType The MIME type of the response to be sent to the client. | ||
* @param parent A `Disposable` object to which this handler is registered for automatic disposal. | ||
* @param headers Optional headers that will be included in the response. | ||
*/ | ||
open class JBCefStreamResourceHandler( | ||
private val myStream: InputStream, | ||
private val myMimeType: String, | ||
parent: Disposable, | ||
private val headers: Map<String, String> = mapOf(), | ||
) : CefResourceHandler, Disposable { | ||
init { | ||
Disposer.register(parent, this) | ||
Check notice on line 35 in plugins/core/jetbrains-community/src/contrib/org/intellij/images/editor/impl/jcef/JBCefStreamResourceHandler.kt
|
||
Check noticeCode scanning / QDJVMC Leaking 'this' in constructor Note
Leaking 'this' in constructor of non-final class JBCefStreamResourceHandler
|
||
} | ||
|
||
override fun processRequest(request: CefRequest, callback: CefCallback): Boolean { | ||
callback.Continue() | ||
return true | ||
} | ||
|
||
override fun getResponseHeaders(response: CefResponse, responseLength: IntRef, redirectUrl: StringRef) { | ||
response.mimeType = myMimeType | ||
response.status = 200 | ||
for (header in headers) { | ||
response.setHeaderByName(header.key, header.value, true /* overwrite */) | ||
} | ||
} | ||
|
||
override fun readResponse(dataOut: ByteArray, bytesToRead: Int, bytesRead: IntRef, callback: CefCallback): Boolean { | ||
try { | ||
bytesRead.set(myStream.read(dataOut, 0, bytesToRead)) | ||
if (bytesRead.get() != -1) { | ||
return true | ||
} | ||
} | ||
catch (_: IOException) { | ||
callback.cancel() | ||
} | ||
bytesRead.set(0) | ||
Disposer.dispose(this) | ||
return false | ||
} | ||
|
||
override fun cancel() { | ||
Disposer.dispose(this) | ||
} | ||
|
||
override fun dispose() { | ||
try { | ||
myStream.close() | ||
} | ||
catch (e: IOException) { | ||
Logger.getInstance(JBCefStreamResourceHandler::class.java).warn("Failed to close the stream", e) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.