OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #ifndef CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ | |
6 #define CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/ref_counted.h" | |
13 #include "base/threading/non_thread_safe.h" | |
14 #include "chrome/common/chrome_plugin_api.h" | |
15 #include "content/common/notification_observer.h" | |
16 #include "content/common/notification_registrar.h" | |
17 | |
18 class ChromePluginLib; | |
19 class MessageLoop; | |
20 namespace net { | |
21 class HttpResponseHeaders; | |
22 } | |
23 | |
24 // A helper struct to ensure the CPRequest data is cleaned up when done. | |
25 // This class is reused for requests made by the browser (and intercepted by the | |
26 // plugin) as well as those made by the plugin. | |
27 struct ScopableCPRequest : public CPRequest { | |
28 template<class T> | |
29 static T GetData(CPRequest* request) { | |
30 return static_cast<T>(static_cast<ScopableCPRequest*>(request)->data); | |
31 } | |
32 | |
33 ScopableCPRequest(const char* url, const char* method, | |
34 CPBrowsingContext context); | |
35 ~ScopableCPRequest(); | |
36 | |
37 void* data; | |
38 }; | |
39 | |
40 // This is a base class for plugin-related objects that need to go away when | |
41 // the plugin unloads. This object also verifies that it is created and | |
42 // destroyed on the same thread. | |
43 class PluginHelper : public NotificationObserver, | |
44 public base::NonThreadSafe { | |
45 public: | |
46 static void DestroyAllHelpersForPlugin(ChromePluginLib* plugin); | |
47 | |
48 explicit PluginHelper(ChromePluginLib* plugin); | |
49 virtual ~PluginHelper(); | |
50 | |
51 // NotificationObserver | |
52 virtual void Observe(NotificationType type, | |
53 const NotificationSource& source, | |
54 const NotificationDetails& details); | |
55 | |
56 protected: | |
57 NotificationRegistrar registrar_; | |
58 | |
59 scoped_refptr<ChromePluginLib> plugin_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(PluginHelper); | |
62 }; | |
63 | |
64 // A class of utility functions for dealing with request responses. | |
65 class PluginResponseUtils { | |
66 public: | |
67 // Helper to convert request load flags from the plugin API to the net API | |
68 // versions. | |
69 static uint32 CPLoadFlagsToNetFlags(uint32 flags); | |
70 | |
71 // Common implementation of a CPR_GetResponseInfo call. | |
72 static int GetResponseInfo( | |
73 const net::HttpResponseHeaders* response_headers, | |
74 CPResponseInfoType type, void* buf, size_t buf_size); | |
75 }; | |
76 | |
77 // Helper to allocate a string using the given CPB_Alloc function. | |
78 inline char* CPB_StringDup(CPB_AllocFunc alloc, const std::string& str) { | |
79 char* cstr = static_cast<char*>(alloc(static_cast<uint32>(str.length() + 1))); | |
80 memcpy(cstr, str.c_str(), str.length() + 1); // Include null terminator. | |
81 return cstr; | |
82 } | |
83 | |
84 CPError CPB_GetCommandLineArgumentsCommon(const char* url, | |
85 std::string* arguments); | |
86 | |
87 void* STDCALL CPB_Alloc(uint32 size); | |
88 void STDCALL CPB_Free(void* memory); | |
89 | |
90 #endif // CHROME_COMMON_CHROME_PLUGIN_UTIL_H_ | |
OLD | NEW |