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/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "blink/public/resources/grit/blink_resources.h" |
14 #include "mojo/services/html_viewer/webthread_impl.h" | 15 #include "mojo/services/html_viewer/webthread_impl.h" |
15 #include "net/base/data_url.h" | 16 #include "net/base/data_url.h" |
16 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 19 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
19 | 20 |
20 namespace html_viewer { | 21 namespace html_viewer { |
21 namespace { | 22 namespace { |
22 | 23 |
23 // TODO(darin): Figure out what our UA should really be. | 24 // TODO(darin): Figure out what our UA should really be. |
24 const char kUserAgentString[] = | 25 const char kUserAgentString[] = |
25 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " | 26 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " |
26 "Chrome/35.0.1916.153 Safari/537.36"; | 27 "Chrome/35.0.1916.153 Safari/537.36"; |
27 | 28 |
| 29 struct DataResource { |
| 30 const char* name; |
| 31 int id; |
| 32 }; |
| 33 |
| 34 const DataResource kDataResources[] = { |
| 35 {"html.css", IDR_UASTYLE_HTML_CSS}, |
| 36 {"quirks.css", IDR_UASTYLE_QUIRKS_CSS}, |
| 37 {"view-source.css", IDR_UASTYLE_VIEW_SOURCE_CSS}, |
| 38 {"themeChromium.css", IDR_UASTYLE_THEME_CHROMIUM_CSS}, |
| 39 #if defined(OS_ANDROID) |
| 40 {"themeChromiumAndroid.css", IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS}, |
| 41 {"mediaControlsAndroid.css", IDR_UASTYLE_MEDIA_CONTROLS_ANDROID_CSS}, |
| 42 #endif |
| 43 #if defined(OS_LINUX) |
| 44 {"themeChromiumLinux.css", IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS}, |
| 45 #endif |
| 46 {"themeChromiumSkia.css", IDR_UASTYLE_THEME_CHROMIUM_SKIA_CSS}, |
| 47 {"themeInputMultipleFields.css", |
| 48 IDR_UASTYLE_THEME_INPUT_MULTIPLE_FIELDS_CSS}, |
| 49 #if defined(OS_MACOSX) |
| 50 {"themeMac.css", IDR_UASTYLE_THEME_MAC_CSS}, |
| 51 #endif |
| 52 {"themeWin.css", IDR_UASTYLE_THEME_WIN_CSS}, |
| 53 {"themeWinQuirks.css", IDR_UASTYLE_THEME_WIN_QUIRKS_CSS}, |
| 54 {"svg.css", IDR_UASTYLE_SVG_CSS}, |
| 55 {"navigationTransitions.css", IDR_UASTYLE_NAVIGATION_TRANSITIONS_CSS}, |
| 56 {"mathml.css", IDR_UASTYLE_MATHML_CSS}, |
| 57 {"mediaControls.css", IDR_UASTYLE_MEDIA_CONTROLS_CSS}, |
| 58 {"fullscreen.css", IDR_UASTYLE_FULLSCREEN_CSS}, |
| 59 {"xhtmlmp.css", IDR_UASTYLE_XHTMLMP_CSS}, |
| 60 {"viewportAndroid.css", IDR_UASTYLE_VIEWPORT_ANDROID_CSS}, |
| 61 {"InspectorOverlayPage.html", IDR_INSPECTOR_OVERLAY_PAGE_HTML}, |
| 62 {"InjectedScriptCanvasModuleSource.js", |
| 63 IDR_INSPECTOR_INJECTED_SCRIPT_CANVAS_MODULE_SOURCE_JS}, |
| 64 {"InjectedScriptSource.js", IDR_INSPECTOR_INJECTED_SCRIPT_SOURCE_JS}, |
| 65 {"DebuggerScriptSource.js", IDR_INSPECTOR_DEBUGGER_SCRIPT_SOURCE_JS}, |
| 66 {"DocumentExecCommand.js", IDR_PRIVATE_SCRIPT_DOCUMENTEXECCOMMAND_JS}, |
| 67 {"DocumentXMLTreeViewer.css", IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_CSS}, |
| 68 {"DocumentXMLTreeViewer.js", IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_JS}, |
| 69 {"HTMLMarqueeElement.js", IDR_PRIVATE_SCRIPT_HTMLMARQUEEELEMENT_JS}, |
| 70 {"PluginPlaceholderElement.js", |
| 71 IDR_PRIVATE_SCRIPT_PLUGINPLACEHOLDERELEMENT_JS}, |
| 72 {"PrivateScriptRunner.js", IDR_PRIVATE_SCRIPT_PRIVATESCRIPTRUNNER_JS}, |
| 73 #ifdef IDR_PICKER_COMMON_JS |
| 74 {"pickerCommon.js", IDR_PICKER_COMMON_JS}, |
| 75 {"pickerCommon.css", IDR_PICKER_COMMON_CSS}, |
| 76 {"calendarPicker.js", IDR_CALENDAR_PICKER_JS}, |
| 77 {"calendarPicker.css", IDR_CALENDAR_PICKER_CSS}, |
| 78 {"pickerButton.css", IDR_PICKER_BUTTON_CSS}, |
| 79 {"suggestionPicker.js", IDR_SUGGESTION_PICKER_JS}, |
| 80 {"suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS}, |
| 81 {"colorSuggestionPicker.js", IDR_COLOR_SUGGESTION_PICKER_JS}, |
| 82 {"colorSuggestionPicker.css", IDR_COLOR_SUGGESTION_PICKER_CSS} |
| 83 #endif |
| 84 }; |
| 85 |
28 class WebWaitableEventImpl : public blink::WebWaitableEvent { | 86 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
29 public: | 87 public: |
30 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | 88 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} |
31 virtual ~WebWaitableEventImpl() {} | 89 virtual ~WebWaitableEventImpl() {} |
32 | 90 |
33 virtual void wait() { impl_->Wait(); } | 91 virtual void wait() { impl_->Wait(); } |
34 virtual void signal() { impl_->Signal(); } | 92 virtual void signal() { impl_->Signal(); } |
35 | 93 |
36 base::WaitableEvent* impl() { | 94 base::WaitableEvent* impl() { |
37 return impl_.get(); | 95 return impl_.get(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { | 194 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { |
137 return &scrollbar_behavior_; | 195 return &scrollbar_behavior_; |
138 } | 196 } |
139 | 197 |
140 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( | 198 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( |
141 const char* category_name) { | 199 const char* category_name) { |
142 static const unsigned char buf[] = "*"; | 200 static const unsigned char buf[] = "*"; |
143 return buf; | 201 return buf; |
144 } | 202 } |
145 | 203 |
| 204 blink::WebData BlinkPlatformImpl::loadResource(const char* resource) { |
| 205 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
| 206 if (!strcmp(resource, kDataResources[i].name)) { |
| 207 int length; |
| 208 const char* data = |
| 209 blink_resource_map_.GetResource(kDataResources[i].id, &length); |
| 210 CHECK(data != nullptr && length > 0); |
| 211 return blink::WebData(data, length); |
| 212 } |
| 213 } |
| 214 NOTREACHED() << "Requested resource is unavailable!"; |
| 215 return blink::WebData(); |
| 216 } |
| 217 |
146 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 218 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { |
147 return NULL; | 219 return NULL; |
148 } | 220 } |
149 | 221 |
150 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { | 222 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { |
151 return NULL; | 223 return NULL; |
152 } | 224 } |
153 | 225 |
154 blink::WebString BlinkPlatformImpl::userAgent() { | 226 blink::WebString BlinkPlatformImpl::userAgent() { |
155 return blink::WebString::fromUTF8(kUserAgentString); | 227 return blink::WebString::fromUTF8(kUserAgentString); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 292 } |
221 | 293 |
222 // static | 294 // static |
223 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 295 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { |
224 WebThreadImplForMessageLoop* impl = | 296 WebThreadImplForMessageLoop* impl = |
225 static_cast<WebThreadImplForMessageLoop*>(thread); | 297 static_cast<WebThreadImplForMessageLoop*>(thread); |
226 delete impl; | 298 delete impl; |
227 } | 299 } |
228 | 300 |
229 } // namespace html_viewer | 301 } // namespace html_viewer |
OLD | NEW |