Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ios / web / public / web_state / web_state.h
blobf4cd76596e904f417bb99f2123497198231e68c2
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.
5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/supports_user_data.h"
13 #include "ios/web/public/referrer.h"
14 #include "ios/web/public/web_state/url_verification_constants.h"
15 #include "ios/web/public/web_view_type.h"
16 #include "ui/base/page_transition_types.h"
17 #include "ui/base/window_open_disposition.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "url/gurl.h"
21 class GURL;
22 class SkBitmap;
24 #if defined(__OBJC__)
25 @class CRWJSInjectionReceiver;
26 @protocol CRWWebViewProxy;
27 typedef id<CRWWebViewProxy> CRWWebViewProxyType;
28 @class UIView;
29 #else
30 class CRWJSInjectionReceiver;
31 typedef void* CRWWebViewProxyType;
32 class UIView;
33 #endif // defined(__OBJC__)
35 namespace base {
36 class DictionaryValue;
39 namespace web {
41 class BrowserState;
42 class NavigationManager;
43 class WebInterstitial;
44 class WebStateObserver;
46 // Core interface for interaction with the web.
47 class WebState : public base::SupportsUserData {
48 public:
49 // Parameters for the OpenURL() method.
50 struct OpenURLParams {
51 OpenURLParams(const GURL& url,
52 const Referrer& referrer,
53 WindowOpenDisposition disposition,
54 ui::PageTransition transition,
55 bool is_renderer_initiated);
56 ~OpenURLParams();
58 // The URL/referrer to be opened.
59 GURL url;
60 Referrer referrer;
62 // The disposition requested by the navigation source.
63 WindowOpenDisposition disposition;
65 // The transition type of navigation.
66 ui::PageTransition transition;
68 // Whether this navigation is initiated by the renderer process.
69 bool is_renderer_initiated;
72 // Callback for |DownloadImage()|.
73 typedef base::Callback<void(
74 int, /* id */
75 int, /* HTTP status code */
76 const GURL&, /* image_url */
77 const std::vector<SkBitmap>&, /* bitmaps */
78 /* The sizes in pixel of the bitmaps before they were resized due to the
79 max bitmap size passed to DownloadImage(). Each entry in the bitmaps
80 vector corresponds to an entry in the sizes vector. If a bitmap was
81 resized, there should be a single returned bitmap. */
82 const std::vector<gfx::Size>&)>
83 ImageDownloadCallback;
85 ~WebState() override {}
87 // The view containing the contents of the current web page. If the view has
88 // been purged due to low memory, this will recreate it. It is up to the
89 // caller to size the view.
90 virtual UIView* GetView() = 0;
92 // Returns the type of the web view associated with this WebState.
93 virtual WebViewType GetWebViewType() const = 0;
95 // Gets the BrowserState associated with this WebState. Can never return null.
96 virtual BrowserState* GetBrowserState() const = 0;
98 // Opens a URL with the given disposition. The transition specifies how this
99 // navigation should be recorded in the history system (for example, typed).
100 virtual void OpenURL(const OpenURLParams& params) = 0;
102 // Gets the NavigationManager associated with this WebState. Can never return
103 // null.
104 virtual NavigationManager* GetNavigationManager() = 0;
106 // Gets the CRWJSInjectionReceiver associated with this WebState.
107 virtual CRWJSInjectionReceiver* GetJSInjectionReceiver() const = 0;
109 // Gets the contents MIME type.
110 virtual const std::string& GetContentsMimeType() const = 0;
112 // Gets the value of the "Content-Language" HTTP header.
113 virtual const std::string& GetContentLanguageHeader() const = 0;
115 // Returns true if the current page is a web view with HTML.
116 virtual bool ContentIsHTML() const = 0;
118 // Returns true if the current page is loading.
119 virtual bool IsLoading() const = 0;
121 // Gets the URL currently being displayed in the URL bar, if there is one.
122 // This URL might be a pending navigation that hasn't committed yet, so it is
123 // not guaranteed to match the current page in this WebState. A typical
124 // example of this is interstitials, which show the URL of the new/loading
125 // page (active) but the security context is of the old page (last committed).
126 virtual const GURL& GetVisibleURL() const = 0;
128 // Gets the last committed URL. It represents the current page that is
129 // displayed in this WebState. It represents the current security context.
130 virtual const GURL& GetLastCommittedURL() const = 0;
132 // Returns the WebState view of the current URL. Moreover, this method
133 // will set the trustLevel enum to the appropriate level from a security point
134 // of view. The caller has to handle the case where |trust_level| is not
135 // appropriate.
136 // TODO(stuartmorgan): Figure out a clean API for this.
137 // See http://crbug.com/457679
138 virtual GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const = 0;
140 // Returns true if a WebInterstitial is currently displayed.
141 virtual bool IsShowingWebInterstitial() const = 0;
143 // Returns the currently visible WebInterstitial if one is shown.
144 virtual WebInterstitial* GetWebInterstitial() const = 0;
146 // Callback used to handle script commands.
147 // The callback must return true if the command was handled, and false
148 // otherwise.
149 // In particular the callback must return false if the command is unexpected
150 // or ill-formatted.
151 // The first parameter is the content of the command, the second parameter is
152 // the URL of the page, and the third parameter is a bool indicating if the
153 // user is currently interacting with the page.
154 typedef base::Callback<bool(const base::DictionaryValue&, const GURL&, bool)>
155 ScriptCommandCallback;
157 // Registers a callback that will be called when a command matching
158 // |command_prefix| is received.
159 virtual void AddScriptCommandCallback(const ScriptCommandCallback& callback,
160 const std::string& command_prefix) = 0;
162 // Removes the callback associated with |command_prefix|.
163 virtual void RemoveScriptCommandCallback(
164 const std::string& command_prefix) = 0;
166 // Returns the current CRWWebViewProxy object.
167 virtual CRWWebViewProxyType GetWebViewProxy() const = 0;
169 // Sends a request to download the given image |url| and returns the unique
170 // id of the download request. When the download is finished, |callback| will
171 // be called with the bitmaps received from the renderer.
172 // If |is_favicon| is true, the cookies are not sent and not accepted during
173 // download.
174 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
175 // from the bitmap results. If there are no bitmap results <=
176 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and
177 // is the only result. A |max_bitmap_size| of 0 means unlimited.
178 // If |bypass_cache| is true, |url| is requested from the server even if it
179 // is present in the browser cache.
180 virtual int DownloadImage(const GURL& url,
181 bool is_favicon,
182 uint32_t max_bitmap_size,
183 bool bypass_cache,
184 const ImageDownloadCallback& callback) = 0;
186 protected:
187 friend class WebStateObserver;
189 // Adds and removes observers for page navigation notifications. The order in
190 // which notifications are sent to observers is undefined. Clients must be
191 // sure to remove the observer before they go away.
192 // TODO(droger): Move these methods to WebStateImpl once it is in ios/.
193 virtual void AddObserver(WebStateObserver* observer) = 0;
194 virtual void RemoveObserver(WebStateObserver* observer) = 0;
196 WebState() {}
199 } // namespace web
201 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_