| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "WebDocument.h" | 35 #include "WebDocument.h" |
| 36 #include "WebFrameClient.h" | 36 #include "WebFrameClient.h" |
| 37 #include "WebFrameImpl.h" | 37 #include "WebFrameImpl.h" |
| 38 #include "WebPlugin.h" | 38 #include "WebPlugin.h" |
| 39 #include "WebPluginContainerImpl.h" | 39 #include "WebPluginContainerImpl.h" |
| 40 #include "WebViewClient.h" | 40 #include "WebViewClient.h" |
| 41 #include "WebViewImpl.h" | 41 #include "WebViewImpl.h" |
| 42 #include "WebWidgetClient.h" | 42 #include "WebWidgetClient.h" |
| 43 #include "core/dom/NodeList.h" | 43 #include "core/dom/NodeList.h" |
| 44 #include "core/html/HTMLPlugInElement.h" | 44 #include "core/html/HTMLPlugInElement.h" |
| 45 #include "core/loader/DocumentLoader.h" | |
| 46 #include "core/loader/EmptyClients.h" | 45 #include "core/loader/EmptyClients.h" |
| 46 #include "core/loader/FrameLoadRequest.h" |
| 47 #include "core/page/FocusController.h" | 47 #include "core/page/FocusController.h" |
| 48 #include "core/frame/FrameView.h" | 48 #include "core/frame/FrameView.h" |
| 49 #include "core/page/Page.h" | 49 #include "core/page/Page.h" |
| 50 #include "core/frame/Settings.h" | 50 #include "core/frame/Settings.h" |
| 51 | 51 |
| 52 using namespace WebCore; | 52 using namespace WebCore; |
| 53 | 53 |
| 54 namespace blink { | 54 namespace blink { |
| 55 | 55 |
| 56 #define addLiteral(literal, writer) writer->addData(literal, sizeof(literal)
- 1) | 56 static const char documentStartLiteral[] = "<!DOCTYPE html><head><meta charset='
UTF-8'></head><body>\n<object type=\""; |
| 57 static const char documentEndLiteral[] = "\"></object></body>\n"; |
| 57 | 58 |
| 58 static inline void addString(const String& str, DocumentWriter* writer) | 59 static void writeDocument(const String& pluginType, const WebURL& url, WebCore::
FrameLoader& loader) |
| 59 { | 60 { |
| 60 CString str8 = str.utf8(); | 61 RefPtr<SharedBuffer> data = SharedBuffer::create(); |
| 61 writer->addData(str8.data(), str8.length()); | 62 data->append(documentStartLiteral, sizeof(documentStartLiteral) - 1); |
| 62 } | 63 data->append(pluginType.utf8().data(), pluginType.utf8().length()); |
| 64 data->append(documentEndLiteral, sizeof(documentEndLiteral) - 1); |
| 63 | 65 |
| 64 static void writeDocument(const String& pluginType, const WebDocument& hostDocum
ent, WebCore::DocumentLoader* loader) | 66 loader.load(FrameLoadRequest(0, ResourceRequest(url.isValid() ? KURL(url) :
blankURL()), SubstituteData(data, "text/html", "UTF-8", KURL(), ForceSynchronous
Load))); |
| 65 { | |
| 66 // Give the new document the same URL as the hose document so that content | |
| 67 // settings and other decisions can be made based on the correct origin. | |
| 68 const WebURL& url = hostDocument.url(); | |
| 69 | |
| 70 DocumentWriter* writer = loader->beginWriting("text/html", "UTF-8", url); | |
| 71 | |
| 72 addLiteral("<!DOCTYPE html><head><meta charset='UTF-8'></head><body>\n", wri
ter); | |
| 73 String objectTag = "<object type=\"" + pluginType + "\"></object>"; | |
| 74 addString(objectTag, writer); | |
| 75 addLiteral("</body>\n", writer); | |
| 76 | |
| 77 loader->endWriting(writer); | |
| 78 } | 67 } |
| 79 | 68 |
| 80 class HelperPluginChromeClient : public EmptyChromeClient { | 69 class HelperPluginChromeClient : public EmptyChromeClient { |
| 81 WTF_MAKE_NONCOPYABLE(HelperPluginChromeClient); | 70 WTF_MAKE_NONCOPYABLE(HelperPluginChromeClient); |
| 82 WTF_MAKE_FAST_ALLOCATED; | 71 WTF_MAKE_FAST_ALLOCATED; |
| 83 | 72 |
| 84 public: | 73 public: |
| 85 explicit HelperPluginChromeClient(WebHelperPluginImpl* widget) | 74 explicit HelperPluginChromeClient(WebHelperPluginImpl* widget) |
| 86 : m_widget(widget) | 75 : m_widget(widget) |
| 87 { | 76 { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 209 |
| 221 m_webView->client()->initializeHelperPluginWebFrame(this); | 210 m_webView->client()->initializeHelperPluginWebFrame(this); |
| 222 | 211 |
| 223 // The page's main frame was set in initializeFrame() as a result of the abo
ve call. | 212 // The page's main frame was set in initializeFrame() as a result of the abo
ve call. |
| 224 Frame* frame = m_page->mainFrame(); | 213 Frame* frame = m_page->mainFrame(); |
| 225 ASSERT(frame); | 214 ASSERT(frame); |
| 226 frame->loader().forceSandboxFlags(SandboxAll & ~SandboxPlugins); | 215 frame->loader().forceSandboxFlags(SandboxAll & ~SandboxPlugins); |
| 227 frame->setView(FrameView::create(frame)); | 216 frame->setView(FrameView::create(frame)); |
| 228 // No need to set a size or make it not transparent. | 217 // No need to set a size or make it not transparent. |
| 229 | 218 |
| 230 writeDocument(pluginType, hostDocument, frame->loader().documentLoader()); | 219 writeDocument(pluginType, hostDocument.url(), frame->loader()); |
| 231 | 220 |
| 232 return true; | 221 return true; |
| 233 } | 222 } |
| 234 | 223 |
| 235 void WebHelperPluginImpl::destroyPage() | 224 void WebHelperPluginImpl::destroyPage() |
| 236 { | 225 { |
| 237 if (!m_page) | 226 if (!m_page) |
| 238 return; | 227 return; |
| 239 | 228 |
| 240 if (m_page->mainFrame()) | 229 if (m_page->mainFrame()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 268 // A WebHelperPluginImpl instance usually has two references. | 257 // A WebHelperPluginImpl instance usually has two references. |
| 269 // - One owned by the instance itself. It represents the visible widget. | 258 // - One owned by the instance itself. It represents the visible widget. |
| 270 // - One owned by the hosting element. It's released when the hosting | 259 // - One owned by the hosting element. It's released when the hosting |
| 271 // element asks the WebHelperPluginImpl to close. | 260 // element asks the WebHelperPluginImpl to close. |
| 272 // We need them because the closing operation is asynchronous and the widget | 261 // We need them because the closing operation is asynchronous and the widget |
| 273 // can be closed while the hosting element is unaware of it. | 262 // can be closed while the hosting element is unaware of it. |
| 274 return adoptRef(new WebHelperPluginImpl(client)).leakRef(); | 263 return adoptRef(new WebHelperPluginImpl(client)).leakRef(); |
| 275 } | 264 } |
| 276 | 265 |
| 277 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |