Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
| 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/android/jni_helper.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "content/public/browser/native_web_keyboard_event.h" | |
| 12 #include "content/public/browser/web_contents_delegate.h" | |
| 13 #include "content/public/common/javascript_message_type.h" | |
| 14 #include "content/public/common/referrer.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "net/base/net_errors.h" | |
| 17 | |
| 18 struct FindMatchRect; | |
| 19 class FindHelper; | |
| 20 | |
| 21 namespace content { | |
| 22 class DownloadItem; | |
| 23 class JavaScriptDialogCreator; | |
| 24 class RenderViewHost; | |
| 25 class WebContents; | |
| 26 } | |
| 27 | |
| 28 using content::NativeWebKeyboardEvent; | |
|
jam
2012/06/08 23:45:09
nit: using statements aren't allowed in headers pe
| |
| 29 | |
| 30 // This enum must be kept in sync with ContentViewClient.java | |
| 31 enum ContentViewClientError { | |
| 32 // Success | |
|
jam
2012/06/08 23:45:09
nit: two space invent
| |
| 33 ERROR_OK = 0, | |
|
jam
2012/06/08 23:45:09
nit: the convention we try to follow in content is
| |
| 34 // Generic error | |
| 35 ERROR_UNKNOWN = -1, | |
| 36 // Server or proxy hostname lookup failed | |
| 37 ERROR_HOST_LOOKUP = -2, | |
| 38 // Unsupported authentication scheme (not basic or digest) | |
| 39 ERROR_UNSUPPORTED_AUTH_SCHEME = -3, | |
| 40 // User authentication failed on server | |
| 41 ERROR_AUTHENTICATION = -4, | |
| 42 // User authentication failed on proxy | |
| 43 ERROR_PROXY_AUTHENTICATION = -5, | |
| 44 // Failed to connect to the server | |
| 45 ERROR_CONNECT = -6, | |
| 46 // Failed to read or write to the server | |
| 47 ERROR_IO = -7, | |
| 48 // Connection timed out | |
| 49 ERROR_TIMEOUT = -8, | |
| 50 // Too many redirects | |
| 51 ERROR_REDIRECT_LOOP = -9, | |
| 52 // Unsupported URI scheme | |
| 53 ERROR_UNSUPPORTED_SCHEME = -10, | |
| 54 // Failed to perform SSL handshake | |
| 55 ERROR_FAILED_SSL_HANDSHAKE = -11, | |
| 56 // Malformed URL | |
| 57 ERROR_BAD_URL = -12, | |
| 58 // Generic file error | |
| 59 ERROR_FILE = -13, | |
| 60 // File not found | |
| 61 ERROR_FILE_NOT_FOUND = -14, | |
| 62 // Too many requests during this load | |
| 63 ERROR_TOO_MANY_REQUESTS = -15, | |
| 64 }; | |
| 65 | |
| 66 // Native mirror of ContentViewClient.java. Uses as a client of | |
| 67 // ContentView, the main FrameLayout on Android. | |
| 68 class ContentViewClient : public content::WebContentsDelegate { | |
|
jam
2012/06/08 23:45:09
nit: new code in content should be in the content
| |
| 69 public: | |
| 70 ContentViewClient(JNIEnv* env, jobject obj); | |
| 71 | |
| 72 static ContentViewClient* CreateNativeContentViewClient(JNIEnv* env, | |
| 73 jobject obj); | |
| 74 | |
| 75 // Called by ContentView: | |
| 76 void OnInternalPageLoadRequest(content::WebContents* source, | |
| 77 const GURL& url); | |
| 78 void OnPageStarted(const GURL& url); | |
| 79 void OnPageFinished(const GURL& url); | |
| 80 void OnLoadStarted(); | |
| 81 void OnLoadStopped(); | |
| 82 void OnReceivedError(int error_code, | |
| 83 const string16& description, | |
| 84 const GURL& url); | |
| 85 void OnReceivedHttpAuthRequest(jobject auth_handler, | |
| 86 const string16& host, | |
| 87 const string16& realm); | |
| 88 void OnDidCommitMainFrame(const GURL& url, | |
| 89 const GURL& base_url); | |
| 90 void OnInterstitialShown(); | |
| 91 void OnInterstitialHidden(); | |
| 92 | |
| 93 void SetFindHelper(FindHelper* find_helper); | |
| 94 void SetJavaScriptDialogCreator( | |
| 95 content::JavaScriptDialogCreator* javascript_dialog_creator); | |
| 96 | |
| 97 bool OnJSModalDialog(content::JavaScriptMessageType type, | |
| 98 bool is_before_unload_dialog, | |
| 99 const GURL& url, | |
| 100 const string16& message, | |
| 101 const string16& default_value); | |
| 102 | |
| 103 // Overridden from WebContentsDelegate: | |
| 104 virtual content::WebContents* OpenURLFromTab( | |
| 105 content::WebContents* source, | |
| 106 const content::OpenURLParams& params) OVERRIDE; | |
| 107 | |
|
jam
2012/06/08 23:45:09
nit: convention is to not have any blank lines bet
| |
| 108 virtual bool ShouldIgnoreNavigation( | |
| 109 content::WebContents* source, | |
| 110 const GURL& url, | |
| 111 const content::Referrer& referrer, | |
| 112 WindowOpenDisposition disposition, | |
| 113 content::PageTransition transition_type) OVERRIDE; | |
| 114 | |
| 115 virtual void NavigationStateChanged(const content::WebContents* source, | |
| 116 unsigned changed_flags) OVERRIDE; | |
| 117 | |
| 118 virtual void AddNewContents(content::WebContents* source, | |
| 119 content::WebContents* new_contents, | |
| 120 WindowOpenDisposition disposition, | |
| 121 const gfx::Rect& initial_pos, | |
| 122 bool user_gesture) OVERRIDE; | |
| 123 | |
| 124 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | |
| 125 | |
| 126 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; | |
| 127 | |
| 128 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | |
| 129 | |
| 130 virtual void LoadProgressChanged(double load_progress) OVERRIDE; | |
| 131 | |
| 132 virtual void CloseContents(content::WebContents* source) OVERRIDE; | |
| 133 | |
| 134 virtual void MoveContents(content::WebContents* source, | |
| 135 const gfx::Rect& pos) OVERRIDE; | |
| 136 | |
| 137 // TODO(merge): WARNING! method no longer available on the base class. | |
| 138 // See http://b/issue?id=5862108 | |
| 139 virtual void URLStarredChanged(content::WebContents* source, bool starred); | |
| 140 | |
| 141 virtual void UpdateTargetURL(content::WebContents* source, | |
| 142 int32 page_id, | |
| 143 const GURL& url) OVERRIDE; | |
| 144 | |
| 145 virtual bool CanDownload(content::RenderViewHost* source, | |
| 146 int request_id, | |
| 147 const std::string& request_method) OVERRIDE; | |
| 148 | |
| 149 virtual void OnStartDownload(content::WebContents* source, | |
| 150 content::DownloadItem* download) OVERRIDE; | |
| 151 | |
| 152 virtual void FindReply(content::WebContents* tab, | |
| 153 int request_id, | |
| 154 int number_of_matches, | |
| 155 const gfx::Rect& selection_rect, | |
| 156 int active_match_ordinal, | |
| 157 bool final_update) OVERRIDE; | |
| 158 | |
| 159 virtual void OnReceiveFindMatchRects(int version, | |
| 160 const std::vector<FindMatchRect>& rects, | |
| 161 const FindMatchRect& active_rect) OVERRID E; | |
|
jam
2012/06/08 23:45:09
nit: here and below, 80 char limit. convention whe
| |
| 162 | |
| 163 virtual bool ShouldOverrideLoading(const GURL& url) OVERRIDE; | |
| 164 | |
| 165 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE ; | |
| 166 | |
| 167 virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRID E; | |
| 168 | |
| 169 virtual void RunFileChooser(content::WebContents* tab, | |
| 170 const content::FileChooserParams& params) OVERRIDE ; | |
| 171 | |
| 172 virtual bool TakeFocus(bool reverse) OVERRIDE; | |
| 173 | |
| 174 virtual ~ContentViewClient(); | |
| 175 | |
| 176 private: | |
| 177 // Get the closest ContentViewClient match to the given Chrome error code. | |
| 178 static ContentViewClientError ToContentViewClientError(int netError); | |
|
jam
2012/06/08 23:45:09
nit: style guide is net_error
| |
| 179 | |
| 180 // We use this to keep track of whether the navigation we get in | |
| 181 // ShouldIgnoreNavigation has been initiated by the ContentView or not. We | |
| 182 // need the GURL, because the active navigation entry doesn't change on | |
| 183 // redirects. | |
| 184 GURL last_requested_navigation_url_; | |
| 185 | |
| 186 // We depend on ContentView.java to hold a ref to the client object. If we | |
| 187 // were to hold a hard ref from native we could end up with a cyclic | |
| 188 // ownership leak (the GC can't collect cycles if part of the cycle is caused | |
| 189 // by native). | |
| 190 JavaObjectWeakGlobalRef weak_java_client_; | |
| 191 | |
| 192 // Used to process find replies. Owned by the ContentView. The ContentView | |
| 193 // NULLs this pointer when the FindHelper goes away. | |
| 194 FindHelper* find_helper_; | |
| 195 | |
| 196 // The object responsible for creating JavaScript dialogs. | |
| 197 content::JavaScriptDialogCreator* javascript_dialog_creator_; | |
| 198 }; | |
| 199 | |
| 200 bool RegisterContentViewClient(JNIEnv* env); | |
| 201 | |
| 202 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | |
| OLD | NEW |