Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/html_viewer/blink_platform_impl.h" | 5 #include "mojo/services/html_viewer/blink_platform_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/path_service.h" | |
| 9 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "blink/public/resources/grit/blink_resources.h" | |
| 14 #include "mojo/services/html_viewer/webthread_impl.h" | 16 #include "mojo/services/html_viewer/webthread_impl.h" |
| 15 #include "net/base/data_url.h" | 17 #include "net/base/data_url.h" |
| 16 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
| 17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 18 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 20 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
| 19 | 21 |
| 20 namespace html_viewer { | 22 namespace html_viewer { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // TODO(darin): Figure out what our UA should really be. | 25 // TODO(darin): Figure out what our UA should really be. |
| 24 const char kUserAgentString[] = | 26 const char kUserAgentString[] = |
| 25 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " | 27 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " |
| 26 "Chrome/35.0.1916.153 Safari/537.36"; | 28 "Chrome/35.0.1916.153 Safari/537.36"; |
| 27 | 29 |
| 30 struct DataResource { | |
| 31 const char* name; | |
| 32 int id; | |
| 33 }; | |
| 34 | |
| 35 const DataResource kDataResources[] = { | |
| 36 {"html.css", IDR_UASTYLE_HTML_CSS}, | |
| 37 {"quirks.css", IDR_UASTYLE_QUIRKS_CSS}, | |
| 38 {"view-source.css", IDR_UASTYLE_VIEW_SOURCE_CSS}, | |
| 39 {"themeChromium.css", IDR_UASTYLE_THEME_CHROMIUM_CSS}, | |
| 40 #if defined(OS_ANDROID) | |
| 41 {"themeChromiumAndroid.css", IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS}, | |
| 42 {"mediaControlsAndroid.css", IDR_UASTYLE_MEDIA_CONTROLS_ANDROID_CSS}, | |
| 43 #endif | |
| 44 #if !defined(OS_WIN) | |
|
jamesr
2015/01/05 23:54:40
we use linux on everything that's not windows?
| |
| 45 {"themeChromiumLinux.css", IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS}, | |
| 46 #endif | |
| 47 {"themeChromiumSkia.css", IDR_UASTYLE_THEME_CHROMIUM_SKIA_CSS}, | |
| 48 {"themeInputMultipleFields.css", | |
| 49 IDR_UASTYLE_THEME_INPUT_MULTIPLE_FIELDS_CSS}, | |
| 50 #if defined(OS_MACOSX) | |
| 51 {"themeMac.css", IDR_UASTYLE_THEME_MAC_CSS}, | |
| 52 #endif | |
| 53 {"themeWin.css", IDR_UASTYLE_THEME_WIN_CSS}, | |
| 54 {"themeWinQuirks.css", IDR_UASTYLE_THEME_WIN_QUIRKS_CSS}, | |
| 55 {"svg.css", IDR_UASTYLE_SVG_CSS}, | |
| 56 {"navigationTransitions.css", IDR_UASTYLE_NAVIGATION_TRANSITIONS_CSS}, | |
| 57 {"mathml.css", IDR_UASTYLE_MATHML_CSS}, | |
| 58 {"mediaControls.css", IDR_UASTYLE_MEDIA_CONTROLS_CSS}, | |
| 59 {"fullscreen.css", IDR_UASTYLE_FULLSCREEN_CSS}, | |
| 60 {"xhtmlmp.css", IDR_UASTYLE_XHTMLMP_CSS}, | |
| 61 {"viewportAndroid.css", IDR_UASTYLE_VIEWPORT_ANDROID_CSS}, | |
| 62 {"InspectorOverlayPage.html", IDR_INSPECTOR_OVERLAY_PAGE_HTML}, | |
| 63 {"InjectedScriptCanvasModuleSource.js", | |
| 64 IDR_INSPECTOR_INJECTED_SCRIPT_CANVAS_MODULE_SOURCE_JS}, | |
| 65 {"InjectedScriptSource.js", IDR_INSPECTOR_INJECTED_SCRIPT_SOURCE_JS}, | |
| 66 {"DebuggerScriptSource.js", IDR_INSPECTOR_DEBUGGER_SCRIPT_SOURCE_JS}, | |
| 67 {"DocumentExecCommand.js", IDR_PRIVATE_SCRIPT_DOCUMENTEXECCOMMAND_JS}, | |
| 68 {"DocumentXMLTreeViewer.css", IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_CSS}, | |
| 69 {"DocumentXMLTreeViewer.js", IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_JS}, | |
| 70 {"HTMLMarqueeElement.js", IDR_PRIVATE_SCRIPT_HTMLMARQUEEELEMENT_JS}, | |
| 71 {"PluginPlaceholderElement.js", | |
| 72 IDR_PRIVATE_SCRIPT_PLUGINPLACEHOLDERELEMENT_JS}, | |
| 73 {"PrivateScriptRunner.js", IDR_PRIVATE_SCRIPT_PRIVATESCRIPTRUNNER_JS}, | |
| 74 #ifdef IDR_PICKER_COMMON_JS | |
| 75 {"pickerCommon.js", IDR_PICKER_COMMON_JS}, | |
| 76 {"pickerCommon.css", IDR_PICKER_COMMON_CSS}, | |
| 77 {"calendarPicker.js", IDR_CALENDAR_PICKER_JS}, | |
| 78 {"calendarPicker.css", IDR_CALENDAR_PICKER_CSS}, | |
| 79 {"pickerButton.css", IDR_PICKER_BUTTON_CSS}, | |
| 80 {"suggestionPicker.js", IDR_SUGGESTION_PICKER_JS}, | |
| 81 {"suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS}, | |
| 82 {"colorSuggestionPicker.js", IDR_COLOR_SUGGESTION_PICKER_JS}, | |
| 83 {"colorSuggestionPicker.css", IDR_COLOR_SUGGESTION_PICKER_CSS} | |
| 84 #endif | |
| 85 }; | |
| 86 | |
| 28 class WebWaitableEventImpl : public blink::WebWaitableEvent { | 87 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
| 29 public: | 88 public: |
| 30 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | 89 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} |
| 31 virtual ~WebWaitableEventImpl() {} | 90 virtual ~WebWaitableEventImpl() {} |
| 32 | 91 |
| 33 virtual void wait() { impl_->Wait(); } | 92 virtual void wait() { impl_->Wait(); } |
| 34 virtual void signal() { impl_->Signal(); } | 93 virtual void signal() { impl_->Signal(); } |
| 35 | 94 |
| 36 base::WaitableEvent* impl() { | 95 base::WaitableEvent* impl() { |
| 37 return impl_.get(); | 96 return impl_.get(); |
| 38 } | 97 } |
| 39 | 98 |
| 40 private: | 99 private: |
| 41 scoped_ptr<base::WaitableEvent> impl_; | 100 scoped_ptr<base::WaitableEvent> impl_; |
| 42 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | 101 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); |
| 43 }; | 102 }; |
| 44 | 103 |
| 45 } // namespace | 104 } // namespace |
| 46 | 105 |
| 47 BlinkPlatformImpl::BlinkPlatformImpl() | 106 BlinkPlatformImpl::BlinkPlatformImpl() |
| 48 : main_loop_(base::MessageLoop::current()), | 107 : main_loop_(base::MessageLoop::current()), |
| 49 shared_timer_func_(NULL), | 108 shared_timer_func_(NULL), |
| 50 shared_timer_fire_time_(0.0), | 109 shared_timer_fire_time_(0.0), |
| 51 shared_timer_fire_time_was_set_while_suspended_(false), | 110 shared_timer_fire_time_was_set_while_suspended_(false), |
| 52 shared_timer_suspended_(0), | 111 shared_timer_suspended_(0), |
| 53 current_thread_slot_(&DestroyCurrentThread) { | 112 current_thread_slot_(&DestroyCurrentThread), |
| 113 data_pack_(ui::SCALE_FACTOR_100P) { | |
| 114 base::FilePath blink_resources_pak_path; | |
| 115 PathService::Get(base::DIR_MODULE, &blink_resources_pak_path); | |
| 116 blink_resources_pak_path = | |
| 117 blink_resources_pak_path.Append(FILE_PATH_LITERAL("blink_resources.pak")); | |
| 118 data_pack_.LoadFromPath(blink_resources_pak_path); | |
| 54 } | 119 } |
| 55 | 120 |
| 56 BlinkPlatformImpl::~BlinkPlatformImpl() { | 121 BlinkPlatformImpl::~BlinkPlatformImpl() { |
| 57 } | 122 } |
| 58 | 123 |
| 59 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { | 124 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { |
| 60 return &mime_registry_; | 125 return &mime_registry_; |
| 61 } | 126 } |
| 62 | 127 |
| 63 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() { | 128 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { | 201 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { |
| 137 return &scrollbar_behavior_; | 202 return &scrollbar_behavior_; |
| 138 } | 203 } |
| 139 | 204 |
| 140 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( | 205 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( |
| 141 const char* category_name) { | 206 const char* category_name) { |
| 142 static const unsigned char buf[] = "*"; | 207 static const unsigned char buf[] = "*"; |
| 143 return buf; | 208 return buf; |
| 144 } | 209 } |
| 145 | 210 |
| 211 blink::WebData BlinkPlatformImpl::loadResource(const char* resource) { | |
| 212 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | |
| 213 if (!strcmp(resource, kDataResources[i].name)) { | |
| 214 base::StringPiece resource; | |
| 215 data_pack_.GetStringPiece(kDataResources[i].id, &resource); | |
| 216 return blink::WebData(resource.data(), resource.size()); | |
| 217 } | |
| 218 } | |
| 219 NOTREACHED() << "Requested resource is unavailable!"; | |
| 220 return blink::WebData(); | |
| 221 } | |
| 222 | |
| 146 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 223 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { |
| 147 return NULL; | 224 return NULL; |
| 148 } | 225 } |
| 149 | 226 |
| 150 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { | 227 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { |
| 151 return NULL; | 228 return NULL; |
| 152 } | 229 } |
| 153 | 230 |
| 154 blink::WebString BlinkPlatformImpl::userAgent() { | 231 blink::WebString BlinkPlatformImpl::userAgent() { |
| 155 return blink::WebString::fromUTF8(kUserAgentString); | 232 return blink::WebString::fromUTF8(kUserAgentString); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } | 297 } |
| 221 | 298 |
| 222 // static | 299 // static |
| 223 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 300 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { |
| 224 WebThreadImplForMessageLoop* impl = | 301 WebThreadImplForMessageLoop* impl = |
| 225 static_cast<WebThreadImplForMessageLoop*>(thread); | 302 static_cast<WebThreadImplForMessageLoop*>(thread); |
| 226 delete impl; | 303 delete impl; |
| 227 } | 304 } |
| 228 | 305 |
| 229 } // namespace html_viewer | 306 } // namespace html_viewer |
| OLD | NEW |