OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ |
| 6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/supports_user_data.h" |
| 12 #include "ios/web/public/referrer.h" |
| 13 #include "ui/base/page_transition_types.h" |
| 14 #include "ui/base/window_open_disposition.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 #if defined(__OBJC__) |
| 20 // TODO(droger): Convert all the public web API to C++. |
| 21 @class CRWJSInjectionReceiver; |
| 22 #else |
| 23 class CRWJSInjectionReceiver; |
| 24 #endif // defined(__OBJC__) |
| 25 |
| 26 namespace base { |
| 27 class DictionaryValue; |
| 28 } |
| 29 |
| 30 namespace web { |
| 31 |
| 32 class BrowserState; |
| 33 class NavigationManager; |
| 34 class WebStateObserver; |
| 35 |
| 36 // Core interface for interaction with the web. |
| 37 class WebState : public base::SupportsUserData { |
| 38 public: |
| 39 // Parameters for the OpenURL() method. |
| 40 struct OpenURLParams { |
| 41 OpenURLParams(const GURL& url, |
| 42 const Referrer& referrer, |
| 43 WindowOpenDisposition disposition, |
| 44 ui::PageTransition transition, |
| 45 bool is_renderer_initiated); |
| 46 ~OpenURLParams(); |
| 47 |
| 48 // The URL/referrer to be opened. |
| 49 GURL url; |
| 50 Referrer referrer; |
| 51 |
| 52 // The disposition requested by the navigation source. |
| 53 WindowOpenDisposition disposition; |
| 54 |
| 55 // The transition type of navigation. |
| 56 ui::PageTransition transition; |
| 57 |
| 58 // Whether this navigation is initiated by the renderer process. |
| 59 bool is_renderer_initiated; |
| 60 }; |
| 61 |
| 62 virtual ~WebState() {} |
| 63 |
| 64 // Gets the BrowserState associated with this WebState. Can never return null. |
| 65 virtual BrowserState* GetBrowserState() const = 0; |
| 66 |
| 67 // Opens a URL with the given disposition. The transition specifies how this |
| 68 // navigation should be recorded in the history system (for example, typed). |
| 69 virtual void OpenURL(const OpenURLParams& params) = 0; |
| 70 |
| 71 // Gets the NavigationManager associated with this WebState. Can never return |
| 72 // NULL. |
| 73 virtual NavigationManager* GetNavigationManager() = 0; |
| 74 |
| 75 // Gets the CRWJSInjectionReceiver associated with this WebState. |
| 76 virtual CRWJSInjectionReceiver* GetJSInjectionReceiver() const = 0; |
| 77 |
| 78 // Gets the contents MIME type. |
| 79 virtual const std::string& GetContentsMimeType() const = 0; |
| 80 |
| 81 // Gets the value of the "Content-Language" HTTP header. |
| 82 virtual const std::string& GetContentLanguageHeader() const = 0; |
| 83 |
| 84 // Returns true if the current view is a web view with HTML. |
| 85 virtual bool ContentIsHTML() const = 0; |
| 86 |
| 87 // Gets the URL currently being displayed in the URL bar, if there is one. |
| 88 // This URL might be a pending navigation that hasn't committed yet, so it is |
| 89 // not guaranteed to match the current page in this WebState. A typical |
| 90 // example of this is interstitials, which show the URL of the new/loading |
| 91 // page (active) but the security context is of the old page (last committed). |
| 92 virtual const GURL& GetVisibleURL() const = 0; |
| 93 |
| 94 // Gets the last committed URL. It represents the current page that is |
| 95 // displayed in this WebState. It represents the current security context. |
| 96 virtual const GURL& GetLastCommittedURL() const = 0; |
| 97 |
| 98 // Callback used to handle script commands. |
| 99 // The callback must return true if the command was handled, and false |
| 100 // otherwise. |
| 101 // In particular the callback must return false if the command is unexpected |
| 102 // or ill-formatted. |
| 103 // The first parameter is the content of the command, the second parameter is |
| 104 // the URL of the page, and the third parameter is a bool indicating if the |
| 105 // user is currently interacting with the page. |
| 106 typedef base::Callback<bool(const base::DictionaryValue&, const GURL&, bool)> |
| 107 ScriptCommandCallback; |
| 108 |
| 109 // Registers a callback that will be called when a command matching |
| 110 // |command_prefix| is received. |
| 111 virtual void AddScriptCommandCallback(const ScriptCommandCallback& callback, |
| 112 const std::string& command_prefix) = 0; |
| 113 |
| 114 // Removes the callback associated with |command_prefix|. |
| 115 virtual void RemoveScriptCommandCallback( |
| 116 const std::string& command_prefix) = 0; |
| 117 |
| 118 protected: |
| 119 friend class WebStateObserver; |
| 120 |
| 121 // Adds and removes observers for page navigation notifications. The order in |
| 122 // which notifications are sent to observers is undefined. Clients must be |
| 123 // sure to remove the observer before they go away. |
| 124 // TODO(droger): Move these methods to WebStateImpl once it is in ios/. |
| 125 virtual void AddObserver(WebStateObserver* observer) = 0; |
| 126 virtual void RemoveObserver(WebStateObserver* observer) = 0; |
| 127 |
| 128 WebState() {} |
| 129 }; |
| 130 |
| 131 } // namespace web |
| 132 |
| 133 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ |
OLD | NEW |