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