QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / public / web_client.h
blobd1eba010660fd3aa1d7af024a95374c3d8ea925f
1 // Copyright 2014 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_CLIENT_H_
6 #define IOS_WEB_PUBLIC_WEB_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/strings/string16.h"
12 #include "base/strings/string_piece.h"
13 #include "ios/web/public/web_view_type.h"
14 #include "ui/base/layout.h"
16 namespace base {
17 class RefCountedStaticMemory;
20 class GURL;
22 #ifdef __OBJC__
23 @class UIWebView;
24 @class NSString;
25 #else
26 class UIWebView;
27 class NSString;
28 #endif
30 namespace web {
32 class BrowserState;
33 class BrowserURLRewriter;
34 class WebClient;
35 class WebMainParts;
37 // Setter and getter for the client. The client should be set early, before any
38 // web code is called.
39 void SetWebClient(WebClient* client);
40 WebClient* GetWebClient();
42 // Interface that the embedder of the web layer implements.
43 class WebClient {
44 public:
45 WebClient();
46 virtual ~WebClient();
48 // Allows the embedder to set a custom WebMainParts implementation for the
49 // browser startup code.
50 virtual WebMainParts* CreateWebMainParts();
52 // Gives the embedder a chance to perform tasks before a web view is created.
53 virtual void PreWebViewCreation() const {}
55 // Gives the embedder a chance to set up the given web view before presenting
56 // it in the UI.
57 virtual void PostWebViewCreation(UIWebView* web_view) const {}
59 // Returns the languages used in the Accept-Languages HTTP header.
60 // Used to decide URL formating.
61 virtual std::string GetAcceptLangs(BrowserState* state) const;
63 // Returns the embedding application locale string.
64 virtual std::string GetApplicationLocale() const;
66 // Returns true if URL has application specific schema. Embedder must return
67 // true for every custom app specific schema it supports. For example Chromium
68 // browser would return true for "chrome://about" URL.
69 virtual bool IsAppSpecificURL(const GURL& url) const;
71 // Returns true if web views can be created using an alloc, init call.
72 // Web view creation using an alloc, init call is disabled by default.
73 // If this is disallowed all web view creation must happen through the
74 // web view creation utils methods that vend a web view.
75 // This is called once (only in debug builds) before the first web view is
76 // created and not called repeatedly.
77 virtual bool AllowWebViewAllocInit() const;
79 // Returns true if all web views that are created need to be associated with
80 // a BrowserState.
81 // This method is only called if the |AllowWebViewAllocInit| returns false.
82 // If this method returns true, web views can only be created
83 // with the BrowserState whose ActiveStateManager is active.
84 // This is called once (only in debug builds) when the first web view is
85 // created and not called repeatedly.
86 virtual bool WebViewsNeedActiveStateManager() const;
88 // Returns text to be displayed for an unsupported plugin.
89 virtual base::string16 GetPluginNotSupportedText() const;
91 // Returns a string describing the embedder product name and version, of the
92 // form "productname/version". Used as part of the user agent string.
93 virtual std::string GetProduct() const;
95 // Returns the user agent. |desktop_user_agent| is true if desktop user agent
96 // is requested.
97 virtual std::string GetUserAgent(bool desktop_user_agent) const;
99 // Returns a string resource given its id.
100 virtual base::string16 GetLocalizedString(int message_id) const;
102 // Returns the contents of a resource in a StringPiece given the resource id.
103 virtual base::StringPiece GetDataResource(int resource_id,
104 ui::ScaleFactor scale_factor) const;
106 // Returns the raw bytes of a scale independent data resource.
107 virtual base::RefCountedStaticMemory* GetDataResourceBytes(
108 int resource_id) const;
110 // Returns a list of additional WebUI schemes, if any. These additional
111 // schemes act as aliases to the about: scheme. The additional schemes may or
112 // may not serve specific WebUI pages depending on the particular
113 // URLDataSourceIOS and its override of
114 // URLDataSourceIOS::ShouldServiceRequest. For all schemes returned here,
115 // view-source is allowed.
116 virtual void GetAdditionalWebUISchemes(
117 std::vector<std::string>* additional_schemes) {}
119 // Gives the embedder a chance to add url rewriters to the BrowserURLRewriter
120 // singleton.
121 virtual void PostBrowserURLRewriterCreation(BrowserURLRewriter* rewriter) {}
123 // Gives the embedder a chance to provide the JavaScript to be injected into
124 // the web view as early as possible. Result must not be nil.
125 virtual NSString* GetEarlyPageScript(WebViewType web_view_type) const;
127 virtual bool IsExternalURLBlockingEnabled() const;
130 } // namespace web
132 #endif // IOS_WEB_PUBLIC_WEB_CLIENT_H_