mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add support for loading extensions (issue #1947)
- Add CefRequestContext::LoadExtension, CefExtension, CefExtensionHandler and related methods/interfaces. - Add chrome://extensions-support that lists supported Chrome APIs. - Add CefBrowserHost::SetAutoResizeEnabled and CefDisplayHandler::OnAutoResize to support browser resize based on preferred web contents size. - views: Add support for custom CefMenuButton popups. - cefclient: Run with `--load-extension=set_page_color` command-line flag for an extension loading example. Add `--use-views` on Windows and Linux for an even better example.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# Color Extension
|
||||
|
||||
Demonstrates basic extension app loading and integration by using a popup to change the page color.
|
||||
|
||||
## Usage
|
||||
|
||||
Run `cefclient --load-extension=set_page_color`.
|
||||
|
||||
When using the Views framework (`--use-views`) an extension icon will be added to the control bar and clicking the icon will open the extension window. When not using the Views framework an extension window will be opened automatically on application start.
|
||||
|
||||
## Implementation
|
||||
|
||||
Based on the [set_page_color](https://developer.chrome.com/extensions/samples#search:browser%20action%20with%20a%20popup) example extension.
|
||||
|
||||
Calls:
|
||||
|
||||
* [tabs.executeScript](https://developer.chrome.com/extensions/tabs#method-executeScript)
|
BIN
tests/cefclient/resources/extensions/set_page_color/icon.png
Normal file
BIN
tests/cefclient/resources/extensions/set_page_color/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 B |
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "A browser action with a popup that changes the page color",
|
||||
"description": "Change the current page color",
|
||||
"version": "1.0",
|
||||
"permissions": [
|
||||
"tabs", "http://*/*", "https://*/*"
|
||||
],
|
||||
"browser_action": {
|
||||
"default_title": "Set this page's color.",
|
||||
"default_icon": "icon.png",
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Set Page Color Popup</title>
|
||||
<style>
|
||||
body {
|
||||
overflow: hidden;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
div:first-child {
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
div {
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
padding: 1px 3px;
|
||||
font-family: sans-serif;
|
||||
font-size: 0.8em;
|
||||
width: 100px;
|
||||
margin-top: 1px;
|
||||
background: #cccccc;
|
||||
}
|
||||
div:hover {
|
||||
background: #aaaaaa;
|
||||
}
|
||||
#red {
|
||||
border: 1px solid red;
|
||||
color: red;
|
||||
}
|
||||
#blue {
|
||||
border: 1px solid blue;
|
||||
color: blue;
|
||||
}
|
||||
#green {
|
||||
border: 1px solid green;
|
||||
color: green;
|
||||
}
|
||||
#yellow {
|
||||
border: 1px solid yellow;
|
||||
color: yellow;
|
||||
}
|
||||
</style>
|
||||
<script src="popup.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="red">red</div>
|
||||
<div id="blue">blue</div>
|
||||
<div id="green">green</div>
|
||||
<div id="yellow">yellow</div>
|
||||
</body>
|
||||
</html>
|
16
tests/cefclient/resources/extensions/set_page_color/popup.js
Normal file
16
tests/cefclient/resources/extensions/set_page_color/popup.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
function click(e) {
|
||||
chrome.tabs.executeScript(null,
|
||||
{code:"document.body.style.backgroundColor='" + e.target.id + "'"});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var divs = document.querySelectorAll('div');
|
||||
for (var i = 0; i < divs.length; i++) {
|
||||
divs[i].addEventListener('click', click);
|
||||
}
|
||||
});
|
@@ -52,6 +52,11 @@ IDS_WINDOW_ICON_1X_PNG BINARY "..\\..\\..\\shared\\resources\\window_icon.1x.png
|
||||
IDS_WINDOW_ICON_2X_PNG BINARY "..\\..\\..\\shared\\resources\\window_icon.2x.png"
|
||||
IDS_XMLHTTPREQUEST_HTML BINARY "..\\xmlhttprequest.html"
|
||||
|
||||
IDS_EXTENSIONS_SET_PAGE_COLOR_ICON_PNG BINARY "..\\extensions\\set_page_color\\icon.png"
|
||||
IDS_EXTENSIONS_SET_PAGE_COLOR_MANIFEST_JSON BINARY "..\\extensions\\set_page_color\\manifest.json"
|
||||
IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_HTML BINARY "..\\extensions\\set_page_color\\popup.html"
|
||||
IDS_EXTENSIONS_SET_PAGE_COLOR_POPUP_JS BINARY "..\\extensions\\set_page_color\\popup.js"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
|
Reference in New Issue
Block a user