blob: 41ee68089ddf442d3994466d2eede74eb62cd85a [file] [log] [blame]
// 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.
#ifndef IOS_WEB_PUBLIC_WEB_CLIENT_H_
#define IOS_WEB_PUBLIC_WEB_CLIENT_H_
#include <string>
#include <vector>
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "ui/base/layout.h"
namespace base {
class RefCountedStaticMemory;
}
class GURL;
#ifdef __OBJC__
@class UIWebView;
#else
class UIWebView;
#endif
namespace web {
class BrowserState;
class BrowserURLRewriter;
class WebClient;
class WebMainParts;
class WebViewFactory;
// Setter and getter for the client. The client should be set early, before any
// web code is called.
void SetWebClient(WebClient* client);
WebClient* GetWebClient();
// Interface that the embedder of the web layer implements.
class WebClient {
public:
WebClient();
virtual ~WebClient();
// Allows the embedder to set a custom WebMainParts implementation for the
// browser startup code.
virtual WebMainParts* CreateWebMainParts();
// Gives the embedder a chance to perform tasks before a web view is created.
virtual void PreWebViewCreation() const {}
// Gives the embedder a chance to set up the given web view before presenting
// it in the UI.
virtual void PostWebViewCreation(UIWebView* web_view) const {}
// Returns a factory that vends WebViews.
virtual WebViewFactory* GetWebViewFactory() const;
// Returns the languages used in the Accept-Languages HTTP header.
// Used to decide URL formating.
virtual std::string GetAcceptLangs(BrowserState* state) const;
// Returns true if URL has application specific schema. Embedder must return
// true for every custom app specific schema it supports. For example Chromium
// browser would return true for "chrome://about" URL.
virtual bool IsAppSpecificURL(const GURL& url) const;
// Returns text to be displayed for an unsupported plug-in.
virtual base::string16 GetPluginNotSupportedText() const;
// Returns a string describing the embedder product name and version, of the
// form "productname/version". Used as part of the user agent string.
virtual std::string GetProduct() const;
// Returns the user agent. |desktop_user_agent| is true if desktop user agent
// is requested.
virtual std::string GetUserAgent(bool desktop_user_agent) const;
// Returns a string resource given its id.
virtual base::string16 GetLocalizedString(int message_id) const;
// Returns the contents of a resource in a StringPiece given the resource id.
virtual base::StringPiece GetDataResource(int resource_id,
ui::ScaleFactor scale_factor) const;
// Returns the raw bytes of a scale independent data resource.
virtual base::RefCountedStaticMemory* GetDataResourceBytes(
int resource_id) const;
// Returns a list of additional WebUI schemes, if any. These additional
// schemes act as aliases to the about: scheme. The additional schemes may or
// may not serve specific WebUI pages depending on the particular
// URLDataSourceIOS and its override of
// URLDataSourceIOS::ShouldServiceRequest. For all schemes returned here,
// view-source is allowed.
virtual void GetAdditionalWebUISchemes(
std::vector<std::string>* additional_schemes) {}
// Gives the embedder a chance to add url rewriters to the BrowserURLRewriter
// singleton.
virtual void PostBrowserURLRewriterCreation(BrowserURLRewriter* rewriter) {}
};
} // namespace web
#endif // IOS_WEB_PUBLIC_WEB_CLIENT_H_