| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include <math.h> | 5 #include <math.h> |
| 6 #include "config.h" | 6 #include "config.h" |
| 7 | 7 |
| 8 #include "FrameView.h" | 8 #include "FrameView.h" |
| 9 #include "ScrollView.h" | 9 #include "ScrollView.h" |
| 10 #include <wtf/Assertions.h> | 10 #include <wtf/Assertions.h> |
| 11 #undef LOG | 11 #undef LOG |
| 12 | 12 |
| 13 #include "webkit/glue/webkitclient_impl.h" | 13 #include "webkit/glue/webkitclient_impl.h" |
| 14 | 14 |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
| 19 #include "base/stats_counters.h" | 19 #include "base/stats_counters.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/trace_event.h" | 21 #include "base/trace_event.h" |
| 22 #include "grit/webkit_resources.h" | 22 #include "grit/webkit_resources.h" |
| 23 #include "grit/webkit_strings.h" | 23 #include "grit/webkit_strings.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "webkit/api/public/WebCookie.h" | 25 #include "webkit/api/public/WebCookie.h" |
| 26 #include "webkit/api/public/WebCursorInfo.h" | |
| 27 #include "webkit/api/public/WebData.h" | 26 #include "webkit/api/public/WebData.h" |
| 28 #include "webkit/api/public/WebFrameClient.h" | 27 #include "webkit/api/public/WebFrameClient.h" |
| 29 #include "webkit/api/public/WebPluginListBuilder.h" | 28 #include "webkit/api/public/WebPluginListBuilder.h" |
| 30 #include "webkit/api/public/WebScreenInfo.h" | 29 #include "webkit/api/public/WebScreenInfo.h" |
| 31 #include "webkit/api/public/WebString.h" | 30 #include "webkit/api/public/WebString.h" |
| 32 #include "webkit/api/public/WebVector.h" | 31 #include "webkit/api/public/WebVector.h" |
| 33 #include "webkit/api/public/WebURL.h" | 32 #include "webkit/api/public/WebURL.h" |
| 34 #include "webkit/api/public/WebViewClient.h" | |
| 35 #include "webkit/api/src/ChromeClientImpl.h" | |
| 36 #include "webkit/api/src/WebFrameImpl.h" | |
| 37 #include "webkit/api/src/WebViewImpl.h" | |
| 38 #include "webkit/api/src/WebWorkerClientImpl.h" | |
| 39 #include "webkit/glue/glue_util.h" | 33 #include "webkit/glue/glue_util.h" |
| 40 #include "webkit/glue/plugins/plugin_instance.h" | 34 #include "webkit/glue/plugins/plugin_instance.h" |
| 41 #include "webkit/glue/webkit_glue.h" | 35 #include "webkit/glue/webkit_glue.h" |
| 42 #include "webkit/glue/webplugininfo.h" | 36 #include "webkit/glue/webplugininfo.h" |
| 43 #include "webkit/glue/websocketstreamhandle_impl.h" | 37 #include "webkit/glue/websocketstreamhandle_impl.h" |
| 44 #include "webkit/glue/weburlloader_impl.h" | 38 #include "webkit/glue/weburlloader_impl.h" |
| 45 | 39 |
| 46 using WebKit::ChromeClientImpl; | |
| 47 using WebKit::WebApplicationCacheHost; | 40 using WebKit::WebApplicationCacheHost; |
| 48 using WebKit::WebApplicationCacheHostClient; | 41 using WebKit::WebApplicationCacheHostClient; |
| 49 using WebKit::WebCookie; | 42 using WebKit::WebCookie; |
| 50 using WebKit::WebCursorInfo; | |
| 51 using WebKit::WebData; | 43 using WebKit::WebData; |
| 52 using WebKit::WebFrameImpl; | |
| 53 using WebKit::WebLocalizedString; | 44 using WebKit::WebLocalizedString; |
| 54 using WebKit::WebPluginListBuilder; | 45 using WebKit::WebPluginListBuilder; |
| 55 using WebKit::WebStorageNamespace; | 46 using WebKit::WebStorageNamespace; |
| 56 using WebKit::WebString; | 47 using WebKit::WebString; |
| 57 using WebKit::WebSocketStreamHandle; | 48 using WebKit::WebSocketStreamHandle; |
| 58 using WebKit::WebThemeEngine; | 49 using WebKit::WebThemeEngine; |
| 59 using WebKit::WebURL; | 50 using WebKit::WebURL; |
| 60 using WebKit::WebURLLoader; | 51 using WebKit::WebURLLoader; |
| 61 using WebKit::WebVector; | 52 using WebKit::WebVector; |
| 62 using WebKit::WebViewImpl; | |
| 63 using WebKit::WebWidgetClient; | |
| 64 using WebKit::WebWorkerClientImpl; | |
| 65 | |
| 66 namespace { | |
| 67 | |
| 68 ChromeClientImpl* ToChromeClient(WebCore::Widget* widget) { | |
| 69 WebCore::FrameView* view; | |
| 70 if (widget->isFrameView()) { | |
| 71 view = static_cast<WebCore::FrameView*>(widget); | |
| 72 } else if (widget->parent() && widget->parent()->isFrameView()) { | |
| 73 view = static_cast<WebCore::FrameView*>(widget->parent()); | |
| 74 } else { | |
| 75 return NULL; | |
| 76 } | |
| 77 | |
| 78 WebCore::Page* page = view->frame() ? view->frame()->page() : NULL; | |
| 79 if (!page) | |
| 80 return NULL; | |
| 81 | |
| 82 return static_cast<ChromeClientImpl*>(page->chrome()->client()); | |
| 83 } | |
| 84 | |
| 85 WebWidgetClient* ToWebWidgetClient(WebCore::Widget* widget) { | |
| 86 ChromeClientImpl* chrome_client = ToChromeClient(widget); | |
| 87 if (!chrome_client || !chrome_client->webview()) | |
| 88 return NULL; | |
| 89 return chrome_client->webview()->client(); | |
| 90 } | |
| 91 | |
| 92 } | |
| 93 | 53 |
| 94 namespace webkit_glue { | 54 namespace webkit_glue { |
| 95 | 55 |
| 96 static int ToMessageID(WebLocalizedString::Name name) { | 56 static int ToMessageID(WebLocalizedString::Name name) { |
| 97 switch (name) { | 57 switch (name) { |
| 98 case WebLocalizedString::SubmitButtonDefaultLabel: | 58 case WebLocalizedString::SubmitButtonDefaultLabel: |
| 99 return IDS_FORM_SUBMIT_LABEL; | 59 return IDS_FORM_SUBMIT_LABEL; |
| 100 case WebLocalizedString::InputElementAltText: | 60 case WebLocalizedString::InputElementAltText: |
| 101 return IDS_FORM_INPUT_ALT; | 61 return IDS_FORM_INPUT_ALT; |
| 102 case WebLocalizedString::ResetButtonDefaultLabel: | 62 case WebLocalizedString::ResetButtonDefaultLabel: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 136 } |
| 177 | 137 |
| 178 WebURLLoader* WebKitClientImpl::createURLLoader() { | 138 WebURLLoader* WebKitClientImpl::createURLLoader() { |
| 179 return new WebURLLoaderImpl(); | 139 return new WebURLLoaderImpl(); |
| 180 } | 140 } |
| 181 | 141 |
| 182 WebSocketStreamHandle* WebKitClientImpl::createSocketStreamHandle() { | 142 WebSocketStreamHandle* WebKitClientImpl::createSocketStreamHandle() { |
| 183 return new WebSocketStreamHandleImpl(); | 143 return new WebSocketStreamHandleImpl(); |
| 184 } | 144 } |
| 185 | 145 |
| 146 WebString WebKitClientImpl::userAgent(const WebURL& url) { |
| 147 return WebString::fromUTF8(webkit_glue::GetUserAgent(url)); |
| 148 } |
| 149 |
| 186 void WebKitClientImpl::getPluginList(bool refresh, | 150 void WebKitClientImpl::getPluginList(bool refresh, |
| 187 WebPluginListBuilder* builder) { | 151 WebPluginListBuilder* builder) { |
| 188 std::vector<WebPluginInfo> plugins; | 152 std::vector<WebPluginInfo> plugins; |
| 189 GetPlugins(refresh, &plugins); | 153 GetPlugins(refresh, &plugins); |
| 190 | 154 |
| 191 for (size_t i = 0; i < plugins.size(); ++i) { | 155 for (size_t i = 0; i < plugins.size(); ++i) { |
| 192 const WebPluginInfo& plugin = plugins[i]; | 156 const WebPluginInfo& plugin = plugins[i]; |
| 193 | 157 |
| 194 builder->addPlugin( | 158 builder->addPlugin( |
| 195 WideToUTF16Hack(plugin.name), | 159 WideToUTF16Hack(plugin.name), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 283 } |
| 320 | 284 |
| 321 void WebKitClientImpl::stopSharedTimer() { | 285 void WebKitClientImpl::stopSharedTimer() { |
| 322 shared_timer_.Stop(); | 286 shared_timer_.Stop(); |
| 323 } | 287 } |
| 324 | 288 |
| 325 void WebKitClientImpl::callOnMainThread(void (*func)()) { | 289 void WebKitClientImpl::callOnMainThread(void (*func)()) { |
| 326 main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func)); | 290 main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func)); |
| 327 } | 291 } |
| 328 | 292 |
| 293 WebStorageNamespace* WebKitClientImpl::createLocalStorageNamespace( |
| 294 const WebString& path, unsigned quota) { |
| 295 NOTREACHED(); |
| 296 return 0; |
| 297 } |
| 298 |
| 299 WebStorageNamespace* WebKitClientImpl::createSessionStorageNamespace() { |
| 300 NOTREACHED(); |
| 301 return 0; |
| 302 } |
| 303 |
| 329 void WebKitClientImpl::dispatchStorageEvent(const WebString& key, | 304 void WebKitClientImpl::dispatchStorageEvent(const WebString& key, |
| 330 const WebString& oldValue, const WebString& newValue, | 305 const WebString& oldValue, const WebString& newValue, |
| 331 const WebString& origin, bool isLocalStorage) { | 306 const WebString& origin, bool isLocalStorage) { |
| 332 NOTREACHED(); | 307 NOTREACHED(); |
| 333 } | 308 } |
| 334 | 309 |
| 335 base::PlatformFile WebKitClientImpl::databaseOpenFile( | 310 base::PlatformFile WebKitClientImpl::databaseOpenFile( |
| 336 const WebKit::WebString& file_name, int desired_flags, | 311 const WebKit::WebString& file_name, int desired_flags, |
| 337 base::PlatformFile* dir_handle) { | 312 base::PlatformFile* dir_handle) { |
| 338 if (dir_handle) | 313 if (dir_handle) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return webkit_glue::FilePathStringToWebString(combined_path.value()); | 380 return webkit_glue::FilePathStringToWebString(combined_path.value()); |
| 406 } | 381 } |
| 407 | 382 |
| 408 bool WebKitClientImpl::makeAllDirectories( | 383 bool WebKitClientImpl::makeAllDirectories( |
| 409 const WebKit::WebString& path) { | 384 const WebKit::WebString& path) { |
| 410 DCHECK(!sandboxEnabled()); | 385 DCHECK(!sandboxEnabled()); |
| 411 FilePath::StringType file_path = webkit_glue::WebStringToFilePathString(path); | 386 FilePath::StringType file_path = webkit_glue::WebStringToFilePathString(path); |
| 412 return file_util::CreateDirectory(FilePath(file_path)); | 387 return file_util::CreateDirectory(FilePath(file_path)); |
| 413 } | 388 } |
| 414 | 389 |
| 390 WebKit::WebString WebKitClientImpl::getAbsolutePath( |
| 391 const WebKit::WebString& path) { |
| 392 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); |
| 393 file_util::AbsolutePath(&file_path); |
| 394 return webkit_glue::FilePathStringToWebString(file_path.value()); |
| 395 } |
| 396 |
| 397 bool WebKitClientImpl::isDirectory(const WebKit::WebString& path) { |
| 398 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); |
| 399 return file_util::DirectoryExists(file_path); |
| 400 } |
| 401 |
| 402 WebKit::WebURL WebKitClientImpl::filePathToURL(const WebKit::WebString& path) { |
| 403 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); |
| 404 GURL file_url = net::FilePathToFileURL(file_path); |
| 405 return webkit_glue::KURLToWebURL(webkit_glue::GURLToKURL(file_url)); |
| 406 } |
| 407 |
| 415 //-------------------------------------------------------------------------- | 408 //-------------------------------------------------------------------------- |
| 409 // BEGIN(TemporaryGlue) |
| 416 | 410 |
| 417 // These are temporary methods that the WebKit layer can use to call to the | 411 // These are temporary methods that the WebKit layer can use to call to the |
| 418 // Glue layer. Once the Glue layer moves entirely into the WebKit layer, these | 412 // Glue layer. Once the Glue layer moves entirely into the WebKit layer, these |
| 419 // methods will be deleted. | 413 // methods will be deleted. |
| 420 | 414 |
| 421 WebKit::WebMediaPlayer* WebKitClientImpl::createWebMediaPlayer( | |
| 422 WebKit::WebMediaPlayerClient* client, WebCore::Frame* frame) { | |
| 423 WebFrameImpl* webframe = WebFrameImpl::fromFrame(frame); | |
| 424 if (!webframe->client()) | |
| 425 return NULL; | |
| 426 | |
| 427 return webframe->client()->createMediaPlayer(webframe, client); | |
| 428 } | |
| 429 | |
| 430 void WebKitClientImpl::setCursorForPlugin( | |
| 431 const WebKit::WebCursorInfo& cursor_info, WebCore::Frame* frame) { | |
| 432 WebCore::Page* page = frame->page(); | |
| 433 if (!page) | |
| 434 return; | |
| 435 | |
| 436 ChromeClientImpl* chrome_client = | |
| 437 static_cast<ChromeClientImpl*>(page->chrome()->client()); | |
| 438 | |
| 439 // A windowless plugin can change the cursor in response to the WM_MOUSEMOVE | |
| 440 // event. We need to reflect the changed cursor in the frame view as the | |
| 441 // mouse is moved in the boundaries of the windowless plugin. | |
| 442 chrome_client->setCursorForPlugin(cursor_info); | |
| 443 } | |
| 444 | |
| 445 void WebKitClientImpl::notifyJSOutOfMemory(WebCore::Frame* frame) { | |
| 446 if (!frame) | |
| 447 return; | |
| 448 | |
| 449 WebFrameImpl* webframe = WebFrameImpl::fromFrame(frame); | |
| 450 if (!webframe->client()) | |
| 451 return; | |
| 452 webframe->client()->didExhaustMemoryAvailableForScript(webframe); | |
| 453 } | |
| 454 | |
| 455 bool WebKitClientImpl::popupsAllowed(NPP npp) { | 415 bool WebKitClientImpl::popupsAllowed(NPP npp) { |
| 456 bool popups_allowed = false; | 416 bool popups_allowed = false; |
| 457 if (npp) { | 417 if (npp) { |
| 458 NPAPI::PluginInstance* plugin_instance = | 418 NPAPI::PluginInstance* plugin_instance = |
| 459 reinterpret_cast<NPAPI::PluginInstance*>(npp->ndata); | 419 reinterpret_cast<NPAPI::PluginInstance*>(npp->ndata); |
| 460 if (plugin_instance) | 420 if (plugin_instance) |
| 461 popups_allowed = plugin_instance->popups_allowed(); | 421 popups_allowed = plugin_instance->popups_allowed(); |
| 462 } | 422 } |
| 463 return popups_allowed; | 423 return popups_allowed; |
| 464 } | 424 } |
| 465 | 425 |
| 466 WebCore::String WebKitClientImpl::uiResourceProtocol() { | 426 WebCore::String WebKitClientImpl::uiResourceProtocol() { |
| 467 return StdStringToString(webkit_glue::GetUIResourceProtocol()); | 427 return StdStringToString(webkit_glue::GetUIResourceProtocol()); |
| 468 } | 428 } |
| 469 | 429 |
| 470 int WebKitClientImpl::screenDepth(WebCore::Widget* widget) { | 430 // END(TemporaryGlue) |
| 471 WebKit::WebWidgetClient* client = ToWebWidgetClient(widget); | 431 //-------------------------------------------------------------------------- |
| 472 if (!client) | |
| 473 return 0; | |
| 474 return client->screenInfo().depth; | |
| 475 } | |
| 476 | |
| 477 int WebKitClientImpl::screenDepthPerComponent(WebCore::Widget* widget) { | |
| 478 WebKit::WebWidgetClient* client = ToWebWidgetClient(widget); | |
| 479 if (!client) | |
| 480 return 0; | |
| 481 return client->screenInfo().depthPerComponent; | |
| 482 } | |
| 483 | |
| 484 bool WebKitClientImpl::screenIsMonochrome(WebCore::Widget* widget) { | |
| 485 WebKit::WebWidgetClient* client = ToWebWidgetClient(widget); | |
| 486 if (!client) | |
| 487 return false; | |
| 488 return client->screenInfo().isMonochrome; | |
| 489 } | |
| 490 | |
| 491 WebCore::IntRect WebKitClientImpl::screenRect(WebCore::Widget* widget) { | |
| 492 WebKit::WebWidgetClient* client = ToWebWidgetClient(widget); | |
| 493 if (!client) | |
| 494 return WebCore::IntRect(); | |
| 495 return ToIntRect(client->screenInfo().rect); | |
| 496 } | |
| 497 | |
| 498 WebCore::IntRect WebKitClientImpl::screenAvailableRect( | |
| 499 WebCore::Widget* widget) { | |
| 500 WebKit::WebWidgetClient* client = ToWebWidgetClient(widget); | |
| 501 if (!client) | |
| 502 return WebCore::IntRect(); | |
| 503 return ToIntRect(client->screenInfo().availableRect); | |
| 504 } | |
| 505 | |
| 506 void WebKitClientImpl::widgetSetCursor(WebCore::Widget* widget, | |
| 507 const WebCore::Cursor& cursor) { | |
| 508 ChromeClientImpl* chrome_client = ToChromeClient(widget); | |
| 509 if (chrome_client) | |
| 510 chrome_client->setCursor(CursorToWebCursorInfo(cursor)); | |
| 511 } | |
| 512 | |
| 513 void WebKitClientImpl::widgetSetFocus(WebCore::Widget* widget) { | |
| 514 ChromeClientImpl* chrome_client = ToChromeClient(widget); | |
| 515 if (chrome_client) | |
| 516 chrome_client->focus(); | |
| 517 } | |
| 518 | |
| 519 WebCore::WorkerContextProxy* WebKitClientImpl::createWorkerContextProxy( | |
| 520 WebCore::Worker* worker) { | |
| 521 return WebWorkerClientImpl::createWorkerContextProxy(worker); | |
| 522 } | |
| 523 | |
| 524 WebStorageNamespace* WebKitClientImpl::createLocalStorageNamespace( | |
| 525 const WebString& path, unsigned quota) { | |
| 526 NOTREACHED(); | |
| 527 return 0; | |
| 528 } | |
| 529 | |
| 530 WebStorageNamespace* WebKitClientImpl::createSessionStorageNamespace() { | |
| 531 NOTREACHED(); | |
| 532 return 0; | |
| 533 } | |
| 534 | |
| 535 WebKit::WebString WebKitClientImpl::getAbsolutePath( | |
| 536 const WebKit::WebString& path) { | |
| 537 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); | |
| 538 file_util::AbsolutePath(&file_path); | |
| 539 return webkit_glue::FilePathStringToWebString(file_path.value()); | |
| 540 } | |
| 541 | |
| 542 bool WebKitClientImpl::isDirectory(const WebKit::WebString& path) { | |
| 543 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); | |
| 544 return file_util::DirectoryExists(file_path); | |
| 545 } | |
| 546 | |
| 547 WebKit::WebURL WebKitClientImpl::filePathToURL(const WebKit::WebString& path) { | |
| 548 FilePath file_path(webkit_glue::WebStringToFilePathString(path)); | |
| 549 GURL file_url = net::FilePathToFileURL(file_path); | |
| 550 return webkit_glue::KURLToWebURL(webkit_glue::GURLToKURL(file_url)); | |
| 551 } | |
| 552 | 432 |
| 553 } // namespace webkit_glue | 433 } // namespace webkit_glue |
| OLD | NEW |