-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move webview package to plugin core (#1872)
- Loading branch information
1 parent
9dac262
commit eddc005
Showing
24 changed files
with
102 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...re/jetbrains-community/src/software/aws/toolkits/jetbrains/core/WebviewResourceHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.core | ||
|
||
import org.cef.browser.CefBrowser | ||
import org.cef.browser.CefFrame | ||
import org.cef.callback.CefCallback | ||
import org.cef.callback.CefSchemeHandlerFactory | ||
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.net.URLConnection | ||
|
||
class WebviewResourceHandlerFactory( | ||
val domain: String, | ||
val assetUri: String | ||
) : CefSchemeHandlerFactory { | ||
override fun create( | ||
browser: CefBrowser?, | ||
frame: CefFrame?, | ||
schemeName: String?, | ||
request: CefRequest?, | ||
): CefResourceHandler? { | ||
val resourceUri = request?.url ?: return null | ||
if (!resourceUri.startsWith(domain)) return null | ||
|
||
val resource = resourceUri.replace(domain, assetUri) | ||
val resourceInputStream = this.javaClass.getResourceAsStream(resource) | ||
|
||
try { | ||
resourceInputStream.use { | ||
if (resourceInputStream != null) { | ||
return AssetResourceHandler(resourceInputStream.readAllBytes()) | ||
} | ||
return null | ||
} | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
} | ||
|
||
class AssetResourceHandler(var data: ByteArray) : CefResourceHandler { | ||
/** | ||
* Factory class for [AssetResourceHandler]. Ignores any request that doesn't begin with | ||
* [AssetResourceHandler.LOCAL_RESOURCE_URL_PREFIX] | ||
*/ | ||
|
||
private var offset = 0 | ||
private var resourceUri: String? = null | ||
override fun processRequest(cefRequest: CefRequest, cefCallback: CefCallback): Boolean { | ||
resourceUri = cefRequest.url | ||
cefCallback.Continue() | ||
return true | ||
} | ||
|
||
override fun getResponseHeaders(cefResponse: CefResponse, intRef: IntRef, stringRef: StringRef) { | ||
intRef.set(data.size) | ||
cefResponse.setHeaderByName("Access-Control-Allow-Origin", "*", true) | ||
val mimeType = if (resourceUri?.endsWith(".wasm") == true) "application/wasm" else URLConnection.getFileNameMap().getContentTypeFor(resourceUri) | ||
if (mimeType != null) cefResponse.mimeType = mimeType | ||
cefResponse.status = 200 | ||
} | ||
|
||
override fun readResponse( | ||
outBuffer: ByteArray, | ||
bytesToRead: Int, | ||
bytesRead: IntRef, | ||
cefCallback: CefCallback, | ||
): Boolean { | ||
if (offset >= data.size) { | ||
cefCallback.cancel() | ||
return false | ||
} | ||
var lenToRead = Math.min(outBuffer.size, bytesToRead) | ||
lenToRead = Math.min(data.size - offset, lenToRead) | ||
System.arraycopy(data, offset, outBuffer, 0, lenToRead) | ||
bytesRead.set(lenToRead) | ||
offset = offset + lenToRead | ||
return true | ||
} | ||
|
||
override fun cancel() {} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,6 @@ tasks.processResources { | |
|
||
tasks.jar { | ||
from(buildGetStartUI) { | ||
into("q-webview") | ||
into("webview") | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
plugins/amazonq/q-webview/package-lock.json → plugins/core/webview/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
plugins/amazonq/q-webview/package.json → plugins/core/webview/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "q-webview", | ||
"name": "webview", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "webpack.config.js", | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters