Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js

Issue 959413003: Implement <webview>.addContentScript/removeContentScript API [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test for the lifetime of content scripts. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This module implements the public-facing API functions for the <webview> tag. 5 // This module implements the public-facing API functions for the <webview> tag.
6 6
7 var WebViewInternal = require('webViewInternal').WebViewInternal; 7 var WebViewInternal = require('webViewInternal').WebViewInternal;
8 var WebViewImpl = require('webView').WebViewImpl; 8 var WebViewImpl = require('webView').WebViewImpl;
9 9
10 // An array of <webview>'s public-facing API methods. Methods without custom 10 // An array of <webview>'s public-facing API methods. Methods without custom
11 // implementations will be given default implementations. Default 11 // implementations will be given default implementations. Default
12 // implementations come from createDefaultApiMethod() in web_view.js. 12 // implementations come from createDefaultApiMethod() in web_view.js.
13 var WEB_VIEW_API_METHODS = [ 13 var WEB_VIEW_API_METHODS = [
14 // Add content scripts for the guest page.
15 'addContentScripts',
16
14 // Navigates to the previous history entry. 17 // Navigates to the previous history entry.
15 'back', 18 'back',
16 19
17 // Returns whether there is a previous history entry to navigate to. 20 // Returns whether there is a previous history entry to navigate to.
18 'canGoBack', 21 'canGoBack',
19 22
20 // Returns whether there is a subsequent history entry to navigate to. 23 // Returns whether there is a subsequent history entry to navigate to.
21 'canGoForward', 24 'canGoForward',
22 25
23 // Clears browsing data for the WebView partition. 26 // Clears browsing data for the WebView partition.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 'isUserAgentOverridden', 60 'isUserAgentOverridden',
58 61
59 // Loads a data URL with a specified base URL used for relative links. 62 // Loads a data URL with a specified base URL used for relative links.
60 // Optionally, a virtual URL can be provided to be shown to the user instead 63 // Optionally, a virtual URL can be provided to be shown to the user instead
61 // of the data URL. 64 // of the data URL.
62 'loadDataWithBaseUrl', 65 'loadDataWithBaseUrl',
63 66
64 // Prints the contents of the webview. 67 // Prints the contents of the webview.
65 'print', 68 'print',
66 69
70 // Removes content scripts for the guest page.
71 'removeContentScripts',
72
67 // Reloads the current top-level page. 73 // Reloads the current top-level page.
68 'reload', 74 'reload',
69 75
70 // Override the user agent string used by the webview for guest page requests. 76 // Override the user agent string used by the webview for guest page requests.
71 'setUserAgentOverride', 77 'setUserAgentOverride',
72 78
73 // Changes the zoom factor of the page. 79 // Changes the zoom factor of the page.
74 'setZoom', 80 'setZoom',
75 81
76 // Changes the zoom mode of the webview. 82 // Changes the zoom mode of the webview.
77 'setZoomMode', 83 'setZoomMode',
78 84
79 // Stops loading the current navigation if one is in progress. 85 // Stops loading the current navigation if one is in progress.
80 'stop', 86 'stop',
81 87
82 // Ends the current find session. 88 // Ends the current find session.
83 'stopFinding', 89 'stopFinding',
84 90
85 // Forcibly kills the guest web page's renderer process. 91 // Forcibly kills the guest web page's renderer process.
86 'terminate' 92 'terminate'
87 ]; 93 ];
88 94
89 // ----------------------------------------------------------------------------- 95 // -----------------------------------------------------------------------------
90 // Custom API method implementations. 96 // Custom API method implementations.
91 97
98 WebViewImpl.prototype.addContentScripts = function() {
99 var args = $Array.concat([this.viewInstanceId], $Array.slice(arguments));
Devlin 2015/04/13 19:21:48 https://developer.mozilla.org/en-US/docs/Web/JavaS
Xi Han 2015/04/14 19:05:52 Not an expert here, just follow the ways other fun
100 return $Function.apply(WebViewInternal.addContentScripts, null, args);
101 };
102
92 WebViewImpl.prototype.back = function(callback) { 103 WebViewImpl.prototype.back = function(callback) {
93 return this.go(-1, callback); 104 return this.go(-1, callback);
94 }; 105 };
95 106
96 WebViewImpl.prototype.canGoBack = function() { 107 WebViewImpl.prototype.canGoBack = function() {
97 return this.entryCount > 1 && this.currentEntryIndex > 0; 108 return this.entryCount > 1 && this.currentEntryIndex > 0;
98 }; 109 };
99 110
100 WebViewImpl.prototype.canGoForward = function() { 111 WebViewImpl.prototype.canGoForward = function() {
101 return this.currentEntryIndex >= 0 && 112 return this.currentEntryIndex >= 0 &&
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 'Error while running webview.loadDataWithBaseUrl: ' + 152 'Error while running webview.loadDataWithBaseUrl: ' +
142 chrome.runtime.lastError.message); 153 chrome.runtime.lastError.message);
143 } 154 }
144 }); 155 });
145 }; 156 };
146 157
147 WebViewImpl.prototype.print = function() { 158 WebViewImpl.prototype.print = function() {
148 return this.executeScript({code: 'window.print();'}); 159 return this.executeScript({code: 'window.print();'});
149 }; 160 };
150 161
162 WebViewImpl.prototype.removeContentScripts = function(var_args) {
163 var args = $Array.concat([this.viewInstanceId], $Array.slice(arguments));
164 return $Function.apply(WebViewInternal.removeContentScripts, null, args);
165 };
166
151 WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) { 167 WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) {
152 this.userAgentOverride = userAgentOverride; 168 this.userAgentOverride = userAgentOverride;
153 if (!this.guest.getId()) { 169 if (!this.guest.getId()) {
154 // If we are not attached yet, then we will pick up the user agent on 170 // If we are not attached yet, then we will pick up the user agent on
155 // attachment. 171 // attachment.
156 return false; 172 return false;
157 } 173 }
158 WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride); 174 WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride);
159 return true; 175 return true;
160 }; 176 };
161 177
162 // ----------------------------------------------------------------------------- 178 // -----------------------------------------------------------------------------
163 179
164 WebViewImpl.getApiMethods = function() { 180 WebViewImpl.getApiMethods = function() {
165 return WEB_VIEW_API_METHODS; 181 return WEB_VIEW_API_METHODS;
166 }; 182 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698