diff options
author | droger <droger@chromium.org> | 2014-12-08 02:44:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-08 10:44:39 +0000 |
commit | 5662df670706ad5b29689b809005f7c985b18d20 (patch) | |
tree | c24228dd6f43b9e8f6a1ddfb01a51a47b985ab9c /ios | |
parent | 631db4a9227a66f9520d23f96d02af5bfebabbd9 (diff) | |
download | chromium_src-5662df670706ad5b29689b809005f7c985b18d20.zip chromium_src-5662df670706ad5b29689b809005f7c985b18d20.tar.gz chromium_src-5662df670706ad5b29689b809005f7c985b18d20.tar.bz2 |
Upstream iOS web API.
This CL upstreams NavigationManager, WebState and
WebStateUserData to match the downstream code.
Review URL: https://codereview.chromium.org/777183002
Cr-Commit-Position: refs/heads/master@{#307218}
Diffstat (limited to 'ios')
-rw-r--r-- | ios/ios.gyp | 1 | ||||
-rw-r--r-- | ios/provider/ios_provider_chrome.gyp | 1 | ||||
-rw-r--r-- | ios/provider/ios_provider_web.gyp | 24 | ||||
-rw-r--r-- | ios/public/provider/chrome/browser/DEPS | 3 | ||||
-rw-r--r-- | ios/public/provider/chrome/browser/browser_state/chrome_browser_state.cc | 2 | ||||
-rw-r--r-- | ios/public/provider/web/web_state.h | 23 | ||||
-rw-r--r-- | ios/web/public/navigation_manager.h | 38 | ||||
-rw-r--r-- | ios/web/public/web_state/web_state.h | 133 | ||||
-rw-r--r-- | ios/web/public/web_state/web_state_user_data.h (renamed from ios/public/provider/web/web_state_user_data.h) | 30 | ||||
-rw-r--r-- | ios/web/web_state/web_state.cc | 24 |
10 files changed, 211 insertions, 68 deletions
diff --git a/ios/ios.gyp b/ios/ios.gyp index 23c62c8..45b87b0 100644 --- a/ios/ios.gyp +++ b/ios/ios.gyp @@ -13,7 +13,6 @@ 'ios_base.gyp:*', 'ios_tests_unit.gyp:*', 'provider/ios_provider_chrome.gyp:*', - 'provider/ios_provider_web.gyp:*', 'web/ios_web.gyp:*', ], }, diff --git a/ios/provider/ios_provider_chrome.gyp b/ios/provider/ios_provider_chrome.gyp index eb8e1f1..dab2785 100644 --- a/ios/provider/ios_provider_chrome.gyp +++ b/ios/provider/ios_provider_chrome.gyp @@ -15,7 +15,6 @@ ], 'dependencies': [ '../../base/base.gyp:base', - 'ios_provider_web.gyp:ios_provider_web', ], }, ], diff --git a/ios/provider/ios_provider_web.gyp b/ios/provider/ios_provider_web.gyp deleted file mode 100644 index df72fb7..0000000 --- a/ios/provider/ios_provider_web.gyp +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -{ - 'variables': { - 'chromium_code': 1, - }, - 'targets': [ - { - 'target_name': 'ios_provider_web', - 'type': 'none', - 'include_dirs': [ - '../..', - ], - 'sources': [ - '../public/provider/web/web_state.h', - '../public/provider/web/web_state_user_data.h', - ], - 'dependencies': [ - '../ios_base.gyp:ios_consumer_base', - ], - }, - ], -} diff --git a/ios/public/provider/chrome/browser/DEPS b/ios/public/provider/chrome/browser/DEPS deleted file mode 100644 index 41a04b1..0000000 --- a/ios/public/provider/chrome/browser/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+ios/public/provider/web", -] diff --git a/ios/public/provider/chrome/browser/browser_state/chrome_browser_state.cc b/ios/public/provider/chrome/browser/browser_state/chrome_browser_state.cc index fc8f705..cde450d 100644 --- a/ios/public/provider/chrome/browser/browser_state/chrome_browser_state.cc +++ b/ios/public/provider/chrome/browser/browser_state/chrome_browser_state.cc @@ -4,8 +4,6 @@ #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" -#include "ios/public/provider/web/web_state.h" - namespace ios { // static diff --git a/ios/public/provider/web/web_state.h b/ios/public/provider/web/web_state.h deleted file mode 100644 index 03917a7..0000000 --- a/ios/public/provider/web/web_state.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_H_ -#define IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_H_ - -#include "base/supports_user_data.h" - -namespace ios { - -// Core interface for interaction with the web. -class WebState : public base::SupportsUserData { - public: - ~WebState() override {} - - protected: - WebState() {} -}; - -} // namespace ios - -#endif // IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_H_ diff --git a/ios/web/public/navigation_manager.h b/ios/web/public/navigation_manager.h new file mode 100644 index 0000000..841a341 --- /dev/null +++ b/ios/web/public/navigation_manager.h @@ -0,0 +1,38 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IOS_WEB_PUBLIC_NAVIGATION_MANAGER_H_ +#define IOS_WEB_PUBLIC_NAVIGATION_MANAGER_H_ + +namespace web { + +class BrowserState; +class NavigationItem; +class WebState; + +// A NavigationManager maintains the back-forward list for a WebState and +// manages all navigation within that list. +// +// Each NavigationManager belongs to one WebState; each WebState has +// exactly one NavigationManager. +class NavigationManager { + public: + virtual ~NavigationManager() {} + + // Gets the BrowserState associated with this NavigationManager. Can never + // return null. + virtual BrowserState* GetBrowserState() const = 0; + + // Gets the WebState associated with this NavigationManager. + virtual WebState* GetWebState() const = 0; + + // Returns the NavigationItem that should be used when displaying info about + // the current entry to the user. It ignores certain pending entries, to + // prevent spoofing attacks using slow-loading navigations. + virtual NavigationItem* GetVisibleItem() const = 0; +}; + +} // namespace web + +#endif // IOS_WEB_PUBLIC_NAVIGATION_MANAGER_H_ diff --git a/ios/web/public/web_state/web_state.h b/ios/web/public/web_state/web_state.h new file mode 100644 index 0000000..519bc21 --- /dev/null +++ b/ios/web/public/web_state/web_state.h @@ -0,0 +1,133 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ +#define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ + +#include <string> + +#include "base/callback_forward.h" +#include "base/supports_user_data.h" +#include "ios/web/public/referrer.h" +#include "ui/base/page_transition_types.h" +#include "ui/base/window_open_disposition.h" +#include "url/gurl.h" + +class GURL; + +#if defined(__OBJC__) +// TODO(droger): Convert all the public web API to C++. +@class CRWJSInjectionReceiver; +#else +class CRWJSInjectionReceiver; +#endif // defined(__OBJC__) + +namespace base { +class DictionaryValue; +} + +namespace web { + +class BrowserState; +class NavigationManager; +class WebStateObserver; + +// Core interface for interaction with the web. +class WebState : public base::SupportsUserData { + public: + // Parameters for the OpenURL() method. + struct OpenURLParams { + OpenURLParams(const GURL& url, + const Referrer& referrer, + WindowOpenDisposition disposition, + ui::PageTransition transition, + bool is_renderer_initiated); + ~OpenURLParams(); + + // The URL/referrer to be opened. + GURL url; + Referrer referrer; + + // The disposition requested by the navigation source. + WindowOpenDisposition disposition; + + // The transition type of navigation. + ui::PageTransition transition; + + // Whether this navigation is initiated by the renderer process. + bool is_renderer_initiated; + }; + + virtual ~WebState() {} + + // Gets the BrowserState associated with this WebState. Can never return null. + virtual BrowserState* GetBrowserState() const = 0; + + // Opens a URL with the given disposition. The transition specifies how this + // navigation should be recorded in the history system (for example, typed). + virtual void OpenURL(const OpenURLParams& params) = 0; + + // Gets the NavigationManager associated with this WebState. Can never return + // NULL. + virtual NavigationManager* GetNavigationManager() = 0; + + // Gets the CRWJSInjectionReceiver associated with this WebState. + virtual CRWJSInjectionReceiver* GetJSInjectionReceiver() const = 0; + + // Gets the contents MIME type. + virtual const std::string& GetContentsMimeType() const = 0; + + // Gets the value of the "Content-Language" HTTP header. + virtual const std::string& GetContentLanguageHeader() const = 0; + + // Returns true if the current view is a web view with HTML. + virtual bool ContentIsHTML() const = 0; + + // Gets the URL currently being displayed in the URL bar, if there is one. + // This URL might be a pending navigation that hasn't committed yet, so it is + // not guaranteed to match the current page in this WebState. A typical + // example of this is interstitials, which show the URL of the new/loading + // page (active) but the security context is of the old page (last committed). + virtual const GURL& GetVisibleURL() const = 0; + + // Gets the last committed URL. It represents the current page that is + // displayed in this WebState. It represents the current security context. + virtual const GURL& GetLastCommittedURL() const = 0; + + // Callback used to handle script commands. + // The callback must return true if the command was handled, and false + // otherwise. + // In particular the callback must return false if the command is unexpected + // or ill-formatted. + // The first parameter is the content of the command, the second parameter is + // the URL of the page, and the third parameter is a bool indicating if the + // user is currently interacting with the page. + typedef base::Callback<bool(const base::DictionaryValue&, const GURL&, bool)> + ScriptCommandCallback; + + // Registers a callback that will be called when a command matching + // |command_prefix| is received. + virtual void AddScriptCommandCallback(const ScriptCommandCallback& callback, + const std::string& command_prefix) = 0; + + // Removes the callback associated with |command_prefix|. + virtual void RemoveScriptCommandCallback( + const std::string& command_prefix) = 0; + + protected: + friend class WebStateObserver; + + // Adds and removes observers for page navigation notifications. The order in + // which notifications are sent to observers is undefined. Clients must be + // sure to remove the observer before they go away. + // TODO(droger): Move these methods to WebStateImpl once it is in ios/. + virtual void AddObserver(WebStateObserver* observer) = 0; + virtual void RemoveObserver(WebStateObserver* observer) = 0; + + WebState() {} +}; + +} // namespace web + +#endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_H_ diff --git a/ios/public/provider/web/web_state_user_data.h b/ios/web/public/web_state/web_state_user_data.h index a326d08..2fbcc4e5 100644 --- a/ios/public/provider/web/web_state_user_data.h +++ b/ios/web/public/web_state/web_state_user_data.h @@ -2,25 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ -#define IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ +#ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_USER_DATA_H_ +#define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_USER_DATA_H_ #include "base/supports_user_data.h" -#include "ios/public/provider/web/web_state.h" +#include "ios/web/public/web_state/web_state.h" -namespace ios { +namespace web { // A base class for classes attached to, and scoped to, the lifetime of a // WebState. For example: // // --- in foo.h --- -// class Foo : public ios::WebStateUserData<Foo> { +// class Foo : public web::WebStateUserData<Foo> { // public: // virtual ~Foo(); // // ... more public stuff here ... // private: -// explicit Foo(ios::WebState* web_state); -// friend class ios::WebStateUserData<Foo>; +// explicit Foo(web::WebState* web_state); +// friend class web::WebStateUserData<Foo>; // // ... more private stuff here ... // } // --- in foo.cc --- @@ -45,11 +45,13 @@ class WebStateUserData : public base::SupportsUserData::Data { static const T* FromWebState(const WebState* web_state) { return static_cast<const T*>(web_state->GetUserData(UserDataKey())); } + // Removes the instance attached to the specified WebState. + static void RemoveFromWebState(WebState* web_state) { + web_state->RemoveUserData(UserDataKey()); + } protected: - static inline void* UserDataKey() { - return &kLocatorKey; - } + static inline void* UserDataKey() { return &kLocatorKey; } private: // The user data key. @@ -64,9 +66,9 @@ class WebStateUserData : public base::SupportsUserData::Data { // specialization. (C++98: 14.7.3.15; C++11: 14.7.3.13) // #define DEFINE_WEB_STATE_USER_DATA_KEY(TYPE) \ -template<> \ -int ios::WebStateUserData<TYPE>::kLocatorKey = 0 + template <> \ + int web::WebStateUserData<TYPE>::kLocatorKey = 0 -} // namespace ios +} // namespace web -#endif // IOS_PUBLIC_PROVIDER_WEB_WEB_STATE_USER_DATA_H_ +#endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_USER_DATA_H_ diff --git a/ios/web/web_state/web_state.cc b/ios/web/web_state/web_state.cc new file mode 100644 index 0000000..509e1e5 --- /dev/null +++ b/ios/web/web_state/web_state.cc @@ -0,0 +1,24 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ios/web/public/web_state/web_state.h" + +namespace web { + +WebState::OpenURLParams::OpenURLParams(const GURL& url, + const Referrer& referrer, + WindowOpenDisposition disposition, + ui::PageTransition transition, + bool is_renderer_initiated) + : url(url), + referrer(referrer), + disposition(disposition), + transition(transition), + is_renderer_initiated(is_renderer_initiated) { +} + +WebState::OpenURLParams::~OpenURLParams() { +} + +} // namespace web |