Fix crash on app list start page contents not existing.
[chromium-blink-merge.git] / ios / web / public / web_client.h
blob41ee68089ddf442d3994466d2eede74eb62cd85a
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 "ui/base/layout.h"
15 namespace base {
16 class RefCountedStaticMemory;
19 class GURL;
21 #ifdef __OBJC__
22 @class UIWebView;
23 #else
24 class UIWebView;
25 #endif
27 namespace web {
29 class BrowserState;
30 class BrowserURLRewriter;
31 class WebClient;
32 class WebMainParts;
33 class WebViewFactory;
35 // Setter and getter for the client. The client should be set early, before any
36 // web code is called.
37 void SetWebClient(WebClient* client);
38 WebClient* GetWebClient();
40 // Interface that the embedder of the web layer implements.
41 class WebClient {
42 public:
43 WebClient();
44 virtual ~WebClient();
46 // Allows the embedder to set a custom WebMainParts implementation for the
47 // browser startup code.
48 virtual WebMainParts* CreateWebMainParts();
50 // Gives the embedder a chance to perform tasks before a web view is created.
51 virtual void PreWebViewCreation() const {}
53 // Gives the embedder a chance to set up the given web view before presenting
54 // it in the UI.
55 virtual void PostWebViewCreation(UIWebView* web_view) const {}
57 // Returns a factory that vends WebViews.
58 virtual WebViewFactory* GetWebViewFactory() const;
60 // Returns the languages used in the Accept-Languages HTTP header.
61 // Used to decide URL formating.
62 virtual std::string GetAcceptLangs(BrowserState* state) const;
64 // Returns true if URL has application specific schema. Embedder must return
65 // true for every custom app specific schema it supports. For example Chromium
66 // browser would return true for "chrome://about" URL.
67 virtual bool IsAppSpecificURL(const GURL& url) const;
69 // Returns text to be displayed for an unsupported plug-in.
70 virtual base::string16 GetPluginNotSupportedText() const;
72 // Returns a string describing the embedder product name and version, of the
73 // form "productname/version". Used as part of the user agent string.
74 virtual std::string GetProduct() const;
76 // Returns the user agent. |desktop_user_agent| is true if desktop user agent
77 // is requested.
78 virtual std::string GetUserAgent(bool desktop_user_agent) const;
80 // Returns a string resource given its id.
81 virtual base::string16 GetLocalizedString(int message_id) const;
83 // Returns the contents of a resource in a StringPiece given the resource id.
84 virtual base::StringPiece GetDataResource(int resource_id,
85 ui::ScaleFactor scale_factor) const;
87 // Returns the raw bytes of a scale independent data resource.
88 virtual base::RefCountedStaticMemory* GetDataResourceBytes(
89 int resource_id) const;
91 // Returns a list of additional WebUI schemes, if any. These additional
92 // schemes act as aliases to the about: scheme. The additional schemes may or
93 // may not serve specific WebUI pages depending on the particular
94 // URLDataSourceIOS and its override of
95 // URLDataSourceIOS::ShouldServiceRequest. For all schemes returned here,
96 // view-source is allowed.
97 virtual void GetAdditionalWebUISchemes(
98 std::vector<std::string>* additional_schemes) {}
100 // Gives the embedder a chance to add url rewriters to the BrowserURLRewriter
101 // singleton.
102 virtual void PostBrowserURLRewriterCreation(BrowserURLRewriter* rewriter) {}
105 } // namespace web
107 #endif // IOS_WEB_PUBLIC_WEB_CLIENT_H_