Commit 9a5cfc93 authored by sdefresne's avatar sdefresne Committed by Commit bot

Upstream web_controller_provider.{h,mm} and block_types.h

WebControllerProvider provides URL-loading and JavaScript injection with
optional dialog suppression.

BUG=459678,429756

Review URL: https://codereview.chromium.org/914993006

Cr-Commit-Position: refs/heads/master@{#317041}
parent 8c1e232e
......@@ -14,6 +14,7 @@
'ios_base.gyp:*',
'ios_tests_unit.gyp:*',
'provider/ios_provider_chrome.gyp:*',
'provider/ios_provider_web.gyp:*',
'web/ios_web.gyp:*',
],
},
......
# 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.
{
'variables': {
'chromium_code': 1,
},
'targets': [
{
'target_name': 'ios_provider_web',
'type': 'static_library',
'include_dirs': [
'../..',
],
'dependencies': [
'../../base/base.gyp:base',
'../web/ios_web.gyp:ios_web',
],
'sources': [
'../public/provider/web/web_controller_provider.h',
'../public/provider/web/web_controller_provider.mm',
],
},
],
}
eugenebut@chromium.org
stuartmorgan@chromium.org
// Copyright 2015 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_CONTROLLER_PROVIDER_H_
#define IOS_PUBLIC_PROVIDER_WEB_WEB_CONTROLLER_PROVIDER_H_
#include "base/memory/scoped_ptr.h"
#include "ios/web/public/block_types.h"
#include "ios/web/public/web_state/web_state_observer.h"
#include "url/gurl.h"
namespace web {
class BrowserState;
class WebState;
}
namespace ios {
class WebControllerProviderFactory;
// Setter and getter for the provider factory. The provider factory should be
// set early, before any component using WebControllerProviders is called.
void SetWebControllerProviderFactory(
WebControllerProviderFactory* provider_factory);
WebControllerProviderFactory* GetWebControllerProviderFactory();
// Interface that provides URL-loading and JavaScript injection with optional
// dialog suppression.
class WebControllerProvider {
public:
// Constructor for a WebControllerProvider backed by a CRWWebController
// initialized with |browser_state|.
explicit WebControllerProvider(web::BrowserState* browser_state);
virtual ~WebControllerProvider();
// Determines whether JavaScript dialogs are allowed.
virtual bool SuppressesDialogs() const;
virtual void SetSuppressesDialogs(bool should_suppress_dialogs) {}
// Triggers a load of |url|.
virtual void LoadURL(const GURL& url) {}
// Returns the WebState associated with this web controller.
virtual web::WebState* GetWebState() const;
// Injects |script| into the previously loaded page, if any, and calls
// |completion| with the result. Calls |completion| with nil parameters
// when there is no previously loaded page.
virtual void InjectScript(const std::string& script,
web::JavaScriptCompletion completion);
};
class WebControllerProviderFactory {
public:
WebControllerProviderFactory();
virtual ~WebControllerProviderFactory();
// Vends WebControllerProviders created using |browser_state|, passing
// ownership to callers.
virtual scoped_ptr<WebControllerProvider> CreateWebControllerProvider(
web::BrowserState* browser_state);
};
} // namespace ios
#endif // IOS_PUBLIC_PROVIDER_WEB_WEB_CONTROLLER_PROVIDER_H_
// Copyright 2015 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/public/provider/web/web_controller_provider.h"
namespace ios {
static WebControllerProviderFactory* g_web_controller_provider_factory;
void SetWebControllerProviderFactory(
WebControllerProviderFactory* provider_factory) {
g_web_controller_provider_factory = provider_factory;
}
WebControllerProviderFactory* GetWebControllerProviderFactory() {
return g_web_controller_provider_factory;
}
WebControllerProvider::WebControllerProvider(web::BrowserState* browser_state) {
}
WebControllerProvider::~WebControllerProvider() {
}
bool WebControllerProvider::SuppressesDialogs() const {
return false;
}
web::WebState* WebControllerProvider::GetWebState() const {
return nullptr;
}
void WebControllerProvider::InjectScript(const std::string& script,
web::JavaScriptCompletion completion) {
if (completion)
completion(nil, nil);
}
WebControllerProviderFactory::WebControllerProviderFactory() {
}
WebControllerProviderFactory::~WebControllerProviderFactory() {
}
scoped_ptr<WebControllerProvider>
WebControllerProviderFactory::CreateWebControllerProvider(
web::BrowserState* browser_state) {
return scoped_ptr<WebControllerProvider>(
new WebControllerProvider(browser_state));
}
} // namespace ios
......@@ -25,6 +25,7 @@
'load_committed_details.cc',
'navigation/navigation_item_impl.h',
'navigation/navigation_item_impl.mm',
'public/block_types.h',
'public/browser_state.h',
'public/favicon_status.cc',
'public/favicon_status.h',
......
// Copyright 2015 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_BLOCK_TYPES_H_
#define IOS_WEB_PUBLIC_BLOCK_TYPES_H_
#import <Foundation/Foundation.h>
namespace web {
// The type of the completion handler block that is called to inform about
// JavaScript evaluation completion.
typedef void (^JavaScriptCompletion)(NSString*, NSError*);
} // namespace
#endif // IOS_WEB_PUBLIC_BLOCK_TYPES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment