| 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 #include "content/browser/android/content_view_client.h" |
| 6 |
| 7 #include <android/keycodes.h> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 11 #include "content/browser/android/content_util.h" |
| 12 #include "content/browser/android/content_view_impl.h" |
| 13 #include "content/browser/android/download_controller.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/common/find_match_rect_android.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/download_item.h" |
| 18 #include "content/public/browser/invalidate_type.h" |
| 19 #include "content/public/browser/page_navigator.h" |
| 20 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/page_transition_types.h" |
| 24 #include "content/public/common/referrer.h" |
| 25 #include "jni/content_view_client_jni.h" |
| 26 #include "net/http/http_request_headers.h" |
| 27 #include "ui/gfx/rect.h" |
| 28 #include "webkit/glue/window_open_disposition.h" |
| 29 |
| 30 using base::android::AttachCurrentThread; |
| 31 using base::android::CheckException; |
| 32 using base::android::ConvertUTF8ToJavaString; |
| 33 using base::android::ConvertUTF16ToJavaString; |
| 34 using base::android::GetClass; |
| 35 using base::android::GetMethodID; |
| 36 using base::android::HasClass; |
| 37 using base::android::ScopedJavaLocalRef; |
| 38 |
| 39 namespace content { |
| 40 |
| 41 ContentViewClient::ContentViewClient(JNIEnv* env, jobject obj) |
| 42 : weak_java_client_(env, obj), |
| 43 find_helper_(NULL), |
| 44 javascript_dialog_creator_(NULL) { |
| 45 } |
| 46 |
| 47 ContentViewClient::~ContentViewClient() { |
| 48 } |
| 49 |
| 50 // static |
| 51 ContentViewClient* ContentViewClient::CreateNativeContentViewClient( |
| 52 JNIEnv* env, jobject obj) { |
| 53 DCHECK(obj); |
| 54 return new ContentViewClient(env, obj); |
| 55 } |
| 56 |
| 57 void ContentViewClient::OnInternalPageLoadRequest( |
| 58 WebContents* source, const GURL& url) { |
| 59 last_requested_navigation_url_ = url; |
| 60 } |
| 61 |
| 62 |
| 63 void ContentViewClient::OnPageStarted(const GURL& url) { |
| 64 JNIEnv* env = AttachCurrentThread(); |
| 65 ScopedJavaLocalRef<jstring> jstring_url = |
| 66 ConvertUTF8ToJavaString(env, url.spec()); |
| 67 Java_ContentViewClient_onPageStarted(env, weak_java_client_.get(env).obj(), |
| 68 jstring_url.obj()); |
| 69 } |
| 70 |
| 71 void ContentViewClient::OnPageFinished(const GURL& url) { |
| 72 if (url == last_requested_navigation_url_) |
| 73 last_requested_navigation_url_ = GURL::EmptyGURL(); |
| 74 |
| 75 JNIEnv* env = AttachCurrentThread(); |
| 76 ScopedJavaLocalRef<jstring> jstring_url = |
| 77 ConvertUTF8ToJavaString(env, url.spec()); |
| 78 |
| 79 Java_ContentViewClient_onPageFinished(env, weak_java_client_.get(env).obj(), |
| 80 jstring_url.obj()); |
| 81 CheckException(env); |
| 82 } |
| 83 |
| 84 void ContentViewClient::OnReceivedError(int error_code, |
| 85 const string16& description, |
| 86 const GURL& url) { |
| 87 JNIEnv* env = AttachCurrentThread(); |
| 88 ScopedJavaLocalRef<jstring> jstring_error_description = |
| 89 ConvertUTF8ToJavaString(env, url.spec()); |
| 90 ScopedJavaLocalRef<jstring> jstring_url = |
| 91 ConvertUTF8ToJavaString(env, url.spec()); |
| 92 |
| 93 Java_ContentViewClient_onReceivedError( |
| 94 env, weak_java_client_.get(env).obj(), |
| 95 ToContentViewClientError(error_code), |
| 96 jstring_error_description.obj(), jstring_url.obj()); |
| 97 } |
| 98 |
| 99 void ContentViewClient::OnReceivedHttpAuthRequest( |
| 100 jobject auth_handler, |
| 101 const string16& host, |
| 102 const string16& realm) { |
| 103 /* TODO(jrg): upstream this once ContentHttpAuthHandler.java is |
| 104 upstreamed, and onReceivedHttpAuthRequest() is upstreamed in |
| 105 ContentViewClient.java */ |
| 106 NOTREACHED(); |
| 107 } |
| 108 |
| 109 void ContentViewClient::OnDidCommitMainFrame(const GURL& url, |
| 110 const GURL& base_url) { |
| 111 JNIEnv* env = AttachCurrentThread(); |
| 112 ScopedJavaLocalRef<jstring> jstring_url = |
| 113 ConvertUTF8ToJavaString(env, url.spec()); |
| 114 ScopedJavaLocalRef<jstring> jstring_base_url = |
| 115 ConvertUTF8ToJavaString(env, base_url.spec()); |
| 116 |
| 117 Java_ContentViewClient_onMainFrameCommitted( |
| 118 env, weak_java_client_.get(env).obj(), |
| 119 jstring_url.obj(), jstring_base_url.obj()); |
| 120 } |
| 121 |
| 122 void ContentViewClient::OnInterstitialShown() { |
| 123 JNIEnv* env = AttachCurrentThread(); |
| 124 Java_ContentViewClient_onInterstitialShown( |
| 125 env, weak_java_client_.get(env).obj()); |
| 126 } |
| 127 |
| 128 void ContentViewClient::OnInterstitialHidden() { |
| 129 JNIEnv* env = AttachCurrentThread(); |
| 130 Java_ContentViewClient_onInterstitialHidden( |
| 131 env, weak_java_client_.get(env).obj()); |
| 132 } |
| 133 |
| 134 void ContentViewClient::SetFindHelper(FindHelper* find_helper) { |
| 135 find_helper_ = find_helper; |
| 136 } |
| 137 |
| 138 void ContentViewClient::SetJavaScriptDialogCreator( |
| 139 JavaScriptDialogCreator* javascript_dialog_creator) { |
| 140 javascript_dialog_creator_ = javascript_dialog_creator; |
| 141 } |
| 142 |
| 143 bool ContentViewClient::OnJSModalDialog(JavaScriptMessageType type, |
| 144 bool is_before_unload_dialog, |
| 145 const GURL& url, |
| 146 const string16& message, |
| 147 const string16& default_value) { |
| 148 JNIEnv* env = AttachCurrentThread(); |
| 149 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(env, url.spec())); |
| 150 ScopedJavaLocalRef<jstring> jmessage(ConvertUTF16ToJavaString(env, message)); |
| 151 |
| 152 // Special case for beforeunload dialogs, as that isn't encoded in the |
| 153 // |type| of the dialog. |
| 154 if (is_before_unload_dialog) { |
| 155 return Java_ContentViewClient_onJsBeforeUnload(env, |
| 156 weak_java_client_.get(env).obj(), |
| 157 jurl.obj(), |
| 158 jmessage.obj()); |
| 159 } |
| 160 |
| 161 switch (type) { |
| 162 case JAVASCRIPT_MESSAGE_TYPE_ALERT: |
| 163 return Java_ContentViewClient_onJsAlert(env, |
| 164 weak_java_client_.get(env).obj(), |
| 165 jurl.obj(), |
| 166 jmessage.obj()); |
| 167 |
| 168 case JAVASCRIPT_MESSAGE_TYPE_CONFIRM: |
| 169 return Java_ContentViewClient_onJsConfirm(env, |
| 170 weak_java_client_.get(env).obj(), |
| 171 jurl.obj(), |
| 172 jmessage.obj()); |
| 173 |
| 174 case JAVASCRIPT_MESSAGE_TYPE_PROMPT: { |
| 175 ScopedJavaLocalRef<jstring> jdefault_value( |
| 176 ConvertUTF16ToJavaString(env, default_value)); |
| 177 return Java_ContentViewClient_onJsPrompt(env, |
| 178 weak_java_client_.get(env).obj(), |
| 179 jurl.obj(), |
| 180 jmessage.obj(), |
| 181 jdefault_value.obj()); |
| 182 } |
| 183 |
| 184 default: |
| 185 NOTREACHED(); |
| 186 return false; |
| 187 } |
| 188 } |
| 189 |
| 190 // ---------------------------------------------------------------------------- |
| 191 // WebContentsDelegate methods |
| 192 // ---------------------------------------------------------------------------- |
| 193 |
| 194 // OpenURLFromTab() will be called when we're performing a browser-intiated |
| 195 // navigation. The most common scenario for this is opening new tabs (see |
| 196 // RenderViewImpl::decidePolicyForNavigation for more details). |
| 197 WebContents* ContentViewClient::OpenURLFromTab( |
| 198 WebContents* source, |
| 199 const OpenURLParams& params) { |
| 200 const GURL& url = params.url; |
| 201 WindowOpenDisposition disposition = params.disposition; |
| 202 PageTransition transition( |
| 203 PageTransitionFromInt(params.transition)); |
| 204 |
| 205 if (!source || (disposition != CURRENT_TAB && |
| 206 disposition != NEW_FOREGROUND_TAB && |
| 207 disposition != NEW_BACKGROUND_TAB && |
| 208 disposition != OFF_THE_RECORD)) { |
| 209 NOTIMPLEMENTED(); |
| 210 return NULL; |
| 211 } |
| 212 |
| 213 if (disposition == NEW_FOREGROUND_TAB || |
| 214 disposition == NEW_BACKGROUND_TAB || |
| 215 disposition == OFF_THE_RECORD) { |
| 216 JNIEnv* env = AttachCurrentThread(); |
| 217 ScopedJavaLocalRef<jstring> java_url = |
| 218 ConvertUTF8ToJavaString(env, url.spec()); |
| 219 Java_ContentViewClient_openNewTab(env, |
| 220 weak_java_client_.get(env).obj(), |
| 221 java_url.obj(), |
| 222 disposition == OFF_THE_RECORD); |
| 223 return NULL; |
| 224 } |
| 225 |
| 226 // TODO(mkosiba): This should be in platform_utils OpenExternal, b/6174564. |
| 227 if (transition == PAGE_TRANSITION_LINK && ShouldOverrideLoading(url)) |
| 228 return NULL; |
| 229 |
| 230 source->GetController().LoadURL(url, params.referrer, transition, |
| 231 std::string()); |
| 232 return source; |
| 233 } |
| 234 |
| 235 // ShouldIgnoreNavigation will be called for every non-local top level |
| 236 // navigation made by the renderer. If true is returned the renderer will |
| 237 // not perform the navigation. This is done by using synchronous IPC so we |
| 238 // should avoid blocking calls from this method. |
| 239 bool ContentViewClient::ShouldIgnoreNavigation( |
| 240 WebContents* source, |
| 241 const GURL& url, |
| 242 const Referrer& referrer, |
| 243 WindowOpenDisposition disposition, |
| 244 PageTransition transition_type) { |
| 245 |
| 246 // Don't override new tabs. |
| 247 if (disposition == NEW_FOREGROUND_TAB || |
| 248 disposition == NEW_BACKGROUND_TAB || |
| 249 disposition == OFF_THE_RECORD) |
| 250 return false; |
| 251 |
| 252 // Don't override the navigation that has just been requested via the |
| 253 // ContentView.loadUrl method. |
| 254 if (url == last_requested_navigation_url_) { |
| 255 last_requested_navigation_url_ = GURL::EmptyGURL(); |
| 256 return false; |
| 257 } |
| 258 |
| 259 return ShouldOverrideLoading(url); |
| 260 } |
| 261 |
| 262 void ContentViewClient::NavigationStateChanged( |
| 263 const WebContents* source, unsigned changed_flags) { |
| 264 if (changed_flags & ( |
| 265 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_TITLE)) { |
| 266 JNIEnv* env = AttachCurrentThread(); |
| 267 Java_ContentViewClient_onTabHeaderStateChanged( |
| 268 env, weak_java_client_.get(env).obj()); |
| 269 } |
| 270 } |
| 271 |
| 272 void ContentViewClient::AddNewContents(WebContents* source, |
| 273 WebContents* new_contents, |
| 274 WindowOpenDisposition disposition, |
| 275 const gfx::Rect& initial_pos, |
| 276 bool user_gesture) { |
| 277 JNIEnv* env = AttachCurrentThread(); |
| 278 bool handled = Java_ContentViewClient_addNewContents( |
| 279 env, |
| 280 weak_java_client_.get(env).obj(), |
| 281 reinterpret_cast<jint>(source), |
| 282 reinterpret_cast<jint>(new_contents), |
| 283 static_cast<jint>(disposition), |
| 284 NULL, |
| 285 user_gesture); |
| 286 if (!handled) |
| 287 delete new_contents; |
| 288 } |
| 289 |
| 290 void ContentViewClient::ActivateContents(WebContents* contents) { |
| 291 // TODO(dtrainor) When doing the merge I came across this. Should we be |
| 292 // activating this tab here? |
| 293 } |
| 294 |
| 295 void ContentViewClient::DeactivateContents(WebContents* contents) { |
| 296 // Do nothing. |
| 297 } |
| 298 |
| 299 void ContentViewClient::LoadingStateChanged(WebContents* source) { |
| 300 JNIEnv* env = AttachCurrentThread(); |
| 301 bool has_stopped = source == NULL || !source->IsLoading(); |
| 302 |
| 303 if (has_stopped) |
| 304 Java_ContentViewClient_onLoadStopped( |
| 305 env, weak_java_client_.get(env).obj()); |
| 306 else |
| 307 Java_ContentViewClient_onLoadStarted( |
| 308 env, weak_java_client_.get(env).obj()); |
| 309 } |
| 310 |
| 311 void ContentViewClient::LoadProgressChanged(double progress) { |
| 312 JNIEnv* env = AttachCurrentThread(); |
| 313 Java_ContentViewClient_onLoadProgressChanged( |
| 314 env, |
| 315 weak_java_client_.get(env).obj(), |
| 316 progress); |
| 317 } |
| 318 |
| 319 void ContentViewClient::CloseContents(WebContents* source) { |
| 320 JNIEnv* env = AttachCurrentThread(); |
| 321 Java_ContentViewClient_closeContents(env, weak_java_client_.get(env).obj()); |
| 322 } |
| 323 |
| 324 void ContentViewClient::MoveContents(WebContents* source, |
| 325 const gfx::Rect& pos) { |
| 326 // Do nothing. |
| 327 } |
| 328 |
| 329 // TODO(merge): WARNING! method no longer available on the base class. |
| 330 // See http://b/issue?id=5862108 |
| 331 void ContentViewClient::URLStarredChanged(WebContents* source, bool starred) { |
| 332 JNIEnv* env = AttachCurrentThread(); |
| 333 Java_ContentViewClient_onUrlStarredChanged(env, |
| 334 weak_java_client_.get(env).obj(), |
| 335 starred); |
| 336 } |
| 337 |
| 338 // This is either called from TabContents::DidNavigateMainFramePostCommit() with |
| 339 // an empty GURL or responding to RenderViewHost::OnMsgUpateTargetURL(). In |
| 340 // Chrome, the latter is not always called, especially not during history |
| 341 // navigation. So we only handle the first case and pass the source TabContents' |
| 342 // url to Java to update the UI. |
| 343 void ContentViewClient::UpdateTargetURL(WebContents* source, |
| 344 int32 page_id, |
| 345 const GURL& url) { |
| 346 if (url.is_empty()) { |
| 347 JNIEnv* env = AttachCurrentThread(); |
| 348 ScopedJavaLocalRef<jstring> java_url = |
| 349 ConvertUTF8ToJavaString(env, source->GetURL().spec()); |
| 350 Java_ContentViewClient_onUpdateUrl(env, |
| 351 weak_java_client_.get(env).obj(), |
| 352 java_url.obj()); |
| 353 } |
| 354 } |
| 355 |
| 356 bool ContentViewClient::CanDownload(RenderViewHost* source, |
| 357 int request_id, |
| 358 const std::string& request_method) { |
| 359 if (request_method == net::HttpRequestHeaders::kGetMethod) { |
| 360 DownloadController::GetInstance()->CreateGETDownload( |
| 361 source, request_id); |
| 362 return false; |
| 363 } |
| 364 return true; |
| 365 } |
| 366 |
| 367 void ContentViewClient::OnStartDownload(WebContents* source, |
| 368 DownloadItem* download) { |
| 369 DownloadController::GetInstance()->OnPostDownloadStarted( |
| 370 source, download); |
| 371 } |
| 372 |
| 373 void ContentViewClient::FindReply(WebContents* web_contents, |
| 374 int request_id, |
| 375 int number_of_matches, |
| 376 const gfx::Rect& selection_rect, |
| 377 int active_match_ordinal, |
| 378 bool final_update) { |
| 379 /* TODO(jrg): upstream this; requires |
| 380 content/browser/android/find_helper.h to be upstreamed */ |
| 381 } |
| 382 |
| 383 void ContentViewClient::OnReceiveFindMatchRects( |
| 384 int version, const std::vector<FindMatchRect>& rects, |
| 385 const FindMatchRect& active_rect) { |
| 386 JNIEnv* env = AttachCurrentThread(); |
| 387 |
| 388 // Constructs an float[] of (left, top, right, bottom) tuples and passes it on |
| 389 // to the Java onReceiveFindMatchRects handler which will use it to create |
| 390 // RectF objects equivalent to the std::vector<FindMatchRect>. |
| 391 ScopedJavaLocalRef<jfloatArray> rect_data(env, |
| 392 env->NewFloatArray(rects.size() * 4)); |
| 393 jfloat* rect_data_floats = env->GetFloatArrayElements(rect_data.obj(), NULL); |
| 394 for (size_t i = 0; i < rects.size(); ++i) { |
| 395 rect_data_floats[4 * i] = rects[i].left; |
| 396 rect_data_floats[4 * i + 1] = rects[i].top; |
| 397 rect_data_floats[4 * i + 2] = rects[i].right; |
| 398 rect_data_floats[4 * i + 3] = rects[i].bottom; |
| 399 } |
| 400 env->ReleaseFloatArrayElements(rect_data.obj(), rect_data_floats, 0); |
| 401 |
| 402 ScopedJavaLocalRef<jobject> active_rect_object; |
| 403 if (active_rect.left < active_rect.right && |
| 404 active_rect.top < active_rect.bottom) { |
| 405 ScopedJavaLocalRef<jclass> rect_clazz = |
| 406 GetClass(env, "android/graphics/RectF"); |
| 407 jmethodID rect_constructor = |
| 408 GetMethodID(env, rect_clazz, "<init>", "(FFFF)V"); |
| 409 active_rect_object.Reset(env, env->NewObject(rect_clazz.obj(), |
| 410 rect_constructor, |
| 411 active_rect.left, |
| 412 active_rect.top, |
| 413 active_rect.right, |
| 414 active_rect.bottom)); |
| 415 DCHECK(!active_rect_object.is_null()); |
| 416 } |
| 417 |
| 418 |
| 419 Java_ContentViewClient_onReceiveFindMatchRects( |
| 420 env, |
| 421 weak_java_client_.get(env).obj(), |
| 422 version, rect_data.obj(), |
| 423 active_rect_object.obj()); |
| 424 } |
| 425 |
| 426 bool ContentViewClient::ShouldOverrideLoading(const GURL& url) { |
| 427 if (!url.is_valid()) |
| 428 return false; |
| 429 |
| 430 JNIEnv* env = AttachCurrentThread(); |
| 431 ScopedJavaLocalRef<jstring> jstring_url = |
| 432 ConvertUTF8ToJavaString(env, url.spec()); |
| 433 bool ret = Java_ContentViewClient_shouldOverrideUrlLoading( |
| 434 env, weak_java_client_.get(env).obj(), jstring_url.obj()); |
| 435 return ret; |
| 436 } |
| 437 |
| 438 void ContentViewClient::HandleKeyboardEvent( |
| 439 const NativeWebKeyboardEvent& event) { |
| 440 /* TODO(jrg): to upstream this implementation, we need these files as well: |
| 441 browser/android/ime_helper.cc |
| 442 browser/android/ime_helper.h |
| 443 browser/renderer_host/native_web_keyboard_event_android.h |
| 444 browser/renderer_host/native_web_keyboard_event_android.cc |
| 445 Also the @CalledByNative handleKeyboardEvent() in ContentViewClient.java. |
| 446 */ |
| 447 NOTREACHED(); |
| 448 } |
| 449 |
| 450 bool ContentViewClient::TakeFocus(bool reverse) { |
| 451 JNIEnv* env = AttachCurrentThread(); |
| 452 return Java_ContentViewClient_takeFocus(env, |
| 453 weak_java_client_.get(env).obj(), |
| 454 reverse); |
| 455 } |
| 456 |
| 457 ContentViewClientError ContentViewClient::ToContentViewClientError( |
| 458 int net_error) { |
| 459 // Note: many net::Error constants don't have an obvious mapping. |
| 460 // These will be handled by the default case, ERROR_UNKNOWN. |
| 461 switch(net_error) { |
| 462 case net::ERR_UNSUPPORTED_AUTH_SCHEME: |
| 463 return CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME; |
| 464 |
| 465 case net::ERR_INVALID_AUTH_CREDENTIALS: |
| 466 case net::ERR_MISSING_AUTH_CREDENTIALS: |
| 467 case net::ERR_MISCONFIGURED_AUTH_ENVIRONMENT: |
| 468 return CONTENT_VIEW_CLIENT_ERROR_AUTHENTICATION; |
| 469 |
| 470 case net::ERR_TOO_MANY_REDIRECTS: |
| 471 return CONTENT_VIEW_CLIENT_ERROR_REDIRECT_LOOP; |
| 472 |
| 473 case net::ERR_UPLOAD_FILE_CHANGED: |
| 474 return CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND; |
| 475 |
| 476 case net::ERR_INVALID_URL: |
| 477 return CONTENT_VIEW_CLIENT_ERROR_BAD_URL; |
| 478 |
| 479 case net::ERR_DISALLOWED_URL_SCHEME: |
| 480 case net::ERR_UNKNOWN_URL_SCHEME: |
| 481 return CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_SCHEME; |
| 482 |
| 483 case net::ERR_IO_PENDING: |
| 484 case net::ERR_NETWORK_IO_SUSPENDED: |
| 485 return CONTENT_VIEW_CLIENT_ERROR_IO; |
| 486 |
| 487 case net::ERR_CONNECTION_TIMED_OUT: |
| 488 case net::ERR_TIMED_OUT: |
| 489 return CONTENT_VIEW_CLIENT_ERROR_TIMEOUT; |
| 490 |
| 491 case net::ERR_FILE_TOO_BIG: |
| 492 return CONTENT_VIEW_CLIENT_ERROR_FILE; |
| 493 |
| 494 case net::ERR_HOST_RESOLVER_QUEUE_TOO_LARGE: |
| 495 case net::ERR_INSUFFICIENT_RESOURCES: |
| 496 case net::ERR_OUT_OF_MEMORY: |
| 497 return CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS; |
| 498 |
| 499 case net::ERR_CONNECTION_CLOSED: |
| 500 case net::ERR_CONNECTION_RESET: |
| 501 case net::ERR_CONNECTION_REFUSED: |
| 502 case net::ERR_CONNECTION_ABORTED: |
| 503 case net::ERR_CONNECTION_FAILED: |
| 504 case net::ERR_SOCKET_NOT_CONNECTED: |
| 505 return CONTENT_VIEW_CLIENT_ERROR_CONNECT; |
| 506 |
| 507 case net::ERR_INTERNET_DISCONNECTED: |
| 508 case net::ERR_ADDRESS_INVALID: |
| 509 case net::ERR_ADDRESS_UNREACHABLE: |
| 510 case net::ERR_NAME_NOT_RESOLVED: |
| 511 case net::ERR_NAME_RESOLUTION_FAILED: |
| 512 return CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP; |
| 513 |
| 514 case net::ERR_SSL_PROTOCOL_ERROR: |
| 515 case net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
| 516 case net::ERR_TUNNEL_CONNECTION_FAILED: |
| 517 case net::ERR_NO_SSL_VERSIONS_ENABLED: |
| 518 case net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH: |
| 519 case net::ERR_SSL_RENEGOTIATION_REQUESTED: |
| 520 case net::ERR_CERT_ERROR_IN_SSL_RENEGOTIATION: |
| 521 case net::ERR_BAD_SSL_CLIENT_AUTH_CERT: |
| 522 case net::ERR_SSL_NO_RENEGOTIATION: |
| 523 case net::ERR_SSL_DECOMPRESSION_FAILURE_ALERT: |
| 524 case net::ERR_SSL_BAD_RECORD_MAC_ALERT: |
| 525 case net::ERR_SSL_UNSAFE_NEGOTIATION: |
| 526 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY: |
| 527 case net::ERR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED: |
| 528 case net::ERR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY: |
| 529 return CONTENT_VIEW_CLIENT_ERROR_FAILED_SSL_HANDSHAKE; |
| 530 |
| 531 case net::ERR_PROXY_AUTH_UNSUPPORTED: |
| 532 case net::ERR_PROXY_AUTH_REQUESTED: |
| 533 case net::ERR_PROXY_CONNECTION_FAILED: |
| 534 case net::ERR_UNEXPECTED_PROXY_AUTH: |
| 535 return CONTENT_VIEW_CLIENT_ERROR_PROXY_AUTHENTICATION; |
| 536 |
| 537 /* The certificate errors are handled by onReceivedSslError |
| 538 * and don't need to be reported here. |
| 539 */ |
| 540 case net::ERR_CERT_COMMON_NAME_INVALID: |
| 541 case net::ERR_CERT_DATE_INVALID: |
| 542 case net::ERR_CERT_AUTHORITY_INVALID: |
| 543 case net::ERR_CERT_CONTAINS_ERRORS: |
| 544 case net::ERR_CERT_NO_REVOCATION_MECHANISM: |
| 545 case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: |
| 546 case net::ERR_CERT_REVOKED: |
| 547 case net::ERR_CERT_INVALID: |
| 548 case net::ERR_CERT_WEAK_SIGNATURE_ALGORITHM: |
| 549 case net::ERR_CERT_NOT_IN_DNS: |
| 550 case net::ERR_CERT_NON_UNIQUE_NAME: |
| 551 return CONTENT_VIEW_CLIENT_ERROR_OK; |
| 552 |
| 553 default: |
| 554 VLOG(1) << "ContentViewClient::ToContentViewClientError: Unknown " |
| 555 << "chromium error: " |
| 556 << net_error; |
| 557 return CONTENT_VIEW_CLIENT_ERROR_UNKNOWN; |
| 558 } |
| 559 } |
| 560 |
| 561 JavaScriptDialogCreator* ContentViewClient::GetJavaScriptDialogCreator() { |
| 562 return javascript_dialog_creator_; |
| 563 } |
| 564 |
| 565 void ContentViewClient::RunFileChooser( |
| 566 WebContents* tab, const FileChooserParams& params) { |
| 567 JNIEnv* env = AttachCurrentThread(); |
| 568 ScopedJavaLocalRef<jobject> jparams = ToJavaFileChooserParams(env, params); |
| 569 Java_ContentViewClient_runFileChooser(env, weak_java_client_.get(env).obj(), |
| 570 jparams.obj()); |
| 571 } |
| 572 |
| 573 // ---------------------------------------------------------------------------- |
| 574 // Native JNI methods |
| 575 // ---------------------------------------------------------------------------- |
| 576 |
| 577 // Register native methods |
| 578 |
| 579 bool RegisterContentViewClient(JNIEnv* env) { |
| 580 if (!HasClass(env, kContentViewClientClassPath)) { |
| 581 DLOG(ERROR) << "Unable to find class ContentViewClient!"; |
| 582 return false; |
| 583 } |
| 584 return RegisterNativesImpl(env); |
| 585 } |
| 586 |
| 587 } // namespace content |
| OLD | NEW |