OLD | NEW |
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 30 matching lines...) Expand all Loading... |
54 'isUserAgentOverridden', | 57 'isUserAgentOverridden', |
55 | 58 |
56 // Loads a data URL with a specified base URL used for relative links. | 59 // Loads a data URL with a specified base URL used for relative links. |
57 // Optionally, a virtual URL can be provided to be shown to the user instead | 60 // Optionally, a virtual URL can be provided to be shown to the user instead |
58 // of the data URL. | 61 // of the data URL. |
59 'loadDataWithBaseUrl', | 62 'loadDataWithBaseUrl', |
60 | 63 |
61 // Prints the contents of the webview. | 64 // Prints the contents of the webview. |
62 'print', | 65 'print', |
63 | 66 |
| 67 // Removes content scripts for the guest page. |
| 68 'removeContentScripts', |
| 69 |
64 // Reloads the current top-level page. | 70 // Reloads the current top-level page. |
65 'reload', | 71 'reload', |
66 | 72 |
67 // Override the user agent string used by the webview for guest page requests. | 73 // Override the user agent string used by the webview for guest page requests. |
68 'setUserAgentOverride', | 74 'setUserAgentOverride', |
69 | 75 |
70 // Changes the zoom factor of the page. | 76 // Changes the zoom factor of the page. |
71 'setZoom', | 77 'setZoom', |
72 | 78 |
73 // Stops loading the current navigation if one is in progress. | 79 // Stops loading the current navigation if one is in progress. |
74 'stop', | 80 'stop', |
75 | 81 |
76 // Ends the current find session. | 82 // Ends the current find session. |
77 'stopFinding', | 83 'stopFinding', |
78 | 84 |
79 // Forcibly kills the guest web page's renderer process. | 85 // Forcibly kills the guest web page's renderer process. |
80 'terminate' | 86 'terminate' |
81 ]; | 87 ]; |
82 | 88 |
83 // ----------------------------------------------------------------------------- | 89 // ----------------------------------------------------------------------------- |
84 // Custom API method implementations. | 90 // Custom API method implementations. |
85 | 91 |
| 92 WebViewImpl.prototype.addContentScripts = function() { |
| 93 var args = $Array.concat([this.viewInstanceId], $Array.slice(arguments)); |
| 94 return $Function.apply(WebViewInternal.addContentScripts, null, args); |
| 95 }; |
| 96 |
86 WebViewImpl.prototype.back = function(callback) { | 97 WebViewImpl.prototype.back = function(callback) { |
87 return this.go(-1, callback); | 98 return this.go(-1, callback); |
88 }; | 99 }; |
89 | 100 |
90 WebViewImpl.prototype.canGoBack = function() { | 101 WebViewImpl.prototype.canGoBack = function() { |
91 return this.entryCount > 1 && this.currentEntryIndex > 0; | 102 return this.entryCount > 1 && this.currentEntryIndex > 0; |
92 }; | 103 }; |
93 | 104 |
94 WebViewImpl.prototype.canGoForward = function() { | 105 WebViewImpl.prototype.canGoForward = function() { |
95 return this.currentEntryIndex >= 0 && | 106 return this.currentEntryIndex >= 0 && |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 'Error while running webview.loadDataWithBaseUrl: ' + | 146 'Error while running webview.loadDataWithBaseUrl: ' + |
136 chrome.runtime.lastError.message); | 147 chrome.runtime.lastError.message); |
137 } | 148 } |
138 }); | 149 }); |
139 }; | 150 }; |
140 | 151 |
141 WebViewImpl.prototype.print = function() { | 152 WebViewImpl.prototype.print = function() { |
142 return this.executeScript({code: 'window.print();'}); | 153 return this.executeScript({code: 'window.print();'}); |
143 }; | 154 }; |
144 | 155 |
| 156 WebViewImpl.prototype.removeContentScripts = function(var_args) { |
| 157 var args = $Array.concat([this.viewInstanceId], $Array.slice(arguments)); |
| 158 return $Function.apply(WebViewInternal.removeContentScripts, null, args); |
| 159 }; |
| 160 |
145 WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) { | 161 WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) { |
146 this.userAgentOverride = userAgentOverride; | 162 this.userAgentOverride = userAgentOverride; |
147 if (!this.guest.getId()) { | 163 if (!this.guest.getId()) { |
148 // If we are not attached yet, then we will pick up the user agent on | 164 // If we are not attached yet, then we will pick up the user agent on |
149 // attachment. | 165 // attachment. |
150 return false; | 166 return false; |
151 } | 167 } |
152 WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride); | 168 WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride); |
153 return true; | 169 return true; |
154 }; | 170 }; |
155 | 171 |
156 // ----------------------------------------------------------------------------- | 172 // ----------------------------------------------------------------------------- |
157 | 173 |
158 WebViewImpl.getApiMethods = function() { | 174 WebViewImpl.getApiMethods = function() { |
159 return WEB_VIEW_API_METHODS; | 175 return WEB_VIEW_API_METHODS; |
160 }; | 176 }; |
OLD | NEW |