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
3 // found in the LICENSE file.
5 // This module implements the public-facing API functions for the <webview> tag.
7 var WebViewInternal = require('webViewInternal').WebViewInternal;
8 var WebViewImpl = require('webView').WebViewImpl;
10 // An array of <webview>'s public-facing API methods. Methods without custom
11 // implementations will be given default implementations. Default
12 // implementations come from createDefaultApiMethod() in web_view.js.
13 var WEB_VIEW_API_METHODS = [
14 // Navigates to the previous history entry.
17 // Returns whether there is a previous history entry to navigate to.
20 // Returns whether there is a subsequent history entry to navigate to.
23 // Clears browsing data for the WebView partition.
26 // Injects JavaScript code into the guest page.
29 // Initiates a find-in-page request.
32 // Navigates to the subsequent history entry.
35 // Returns Chrome's internal process ID for the guest web page's current
39 // Returns the user agent string used by the webview for guest page requests.
42 // Gets the current zoom factor.
45 // Navigates to a history entry using a history index relative to the current
49 // Injects CSS into the guest page.
52 // Indicates whether or not the webview's user agent string has been
54 'isUserAgentOverridden',
56 // Prints the contents of the webview.
59 // Reloads the current top-level page.
62 // Override the user agent string used by the webview for guest page requests.
63 'setUserAgentOverride',
65 // Changes the zoom factor of the page.
68 // Stops loading the current navigation if one is in progress.
71 // Ends the current find session.
74 // Forcibly kills the guest web page's renderer process.
78 // -----------------------------------------------------------------------------
79 // Custom API method implementations.
81 WebViewImpl.prototype.back = function(callback) {
82 return this.go(-1, callback);
85 WebViewImpl.prototype.canGoBack = function() {
86 return this.entryCount > 1 && this.currentEntryIndex > 0;
89 WebViewImpl.prototype.canGoForward = function() {
90 return this.currentEntryIndex >= 0 &&
91 this.currentEntryIndex < (this.entryCount - 1);
94 WebViewImpl.prototype.executeScript = function(var_args) {
95 return this.executeCode(WebViewInternal.executeScript,
96 $Array.slice(arguments));
99 WebViewImpl.prototype.forward = function(callback) {
100 return this.go(1, callback);
103 WebViewImpl.prototype.getProcessId = function() {
104 return this.processId;
107 WebViewImpl.prototype.getUserAgent = function() {
108 return this.userAgentOverride || navigator.userAgent;
111 WebViewImpl.prototype.insertCSS = function(var_args) {
112 return this.executeCode(WebViewInternal.insertCSS, $Array.slice(arguments));
115 WebViewImpl.prototype.isUserAgentOverridden = function() {
116 return !!this.userAgentOverride &&
117 this.userAgentOverride != navigator.userAgent;
120 WebViewImpl.prototype.print = function() {
121 return this.executeScript({code: 'window.print();'});
124 WebViewImpl.prototype.setUserAgentOverride = function(userAgentOverride) {
125 this.userAgentOverride = userAgentOverride;
126 if (!this.guest.getId()) {
127 // If we are not attached yet, then we will pick up the user agent on
131 WebViewInternal.overrideUserAgent(this.guest.getId(), userAgentOverride);
135 // -----------------------------------------------------------------------------
137 WebViewImpl.getApiMethods = function() {
138 return WEB_VIEW_API_METHODS;