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