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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_
6 #define CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/debug/trace_event.h"
10 #include "base/platform_file.h"
11 #include "base/timer/timer.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/Platform.h"
14 #include "third_party/WebKit/public/platform/WebURLError.h"
15 #include "ui/base/layout.h"
16 #include "webkit/child/resource_loader_bridge.h"
23 class WebSocketStreamHandle
;
28 class WebSocketStreamHandleDelegate
;
29 class WebSocketStreamHandleBridge
;
31 class CONTENT_EXPORT BlinkPlatformImpl
32 : NON_EXPORTED_BASE(public blink::Platform
) {
35 virtual ~BlinkPlatformImpl();
37 // Platform methods (partial implementation):
38 virtual base::PlatformFile
databaseOpenFile(
39 const blink::WebString
& vfs_file_name
, int desired_flags
);
40 virtual int databaseDeleteFile(const blink::WebString
& vfs_file_name
,
42 virtual long databaseGetFileAttributes(
43 const blink::WebString
& vfs_file_name
);
44 virtual long long databaseGetFileSize(const blink::WebString
& vfs_file_name
);
45 virtual long long databaseGetSpaceAvailableForOrigin(
46 const blink::WebString
& origin_identifier
);
47 virtual blink::WebString
signedPublicKeyAndChallengeString(
48 unsigned key_size_index
, const blink::WebString
& challenge
,
49 const blink::WebURL
& url
);
50 virtual size_t memoryUsageMB();
51 virtual size_t actualMemoryUsageMB();
52 virtual size_t physicalMemoryMB();
53 virtual size_t numberOfProcessors();
55 virtual void startHeapProfiling(const blink::WebString
& prefix
);
56 virtual void stopHeapProfiling() OVERRIDE
;
57 virtual void dumpHeapProfiling(const blink::WebString
& reason
);
58 virtual blink::WebString
getHeapProfile() OVERRIDE
;
60 virtual bool processMemorySizesInBytes(size_t* private_bytes
,
61 size_t* shared_bytes
);
62 virtual bool memoryAllocatorWasteInBytes(size_t* size
);
63 virtual size_t maxDecodedImageBytes() OVERRIDE
;
64 virtual blink::WebURLLoader
* createURLLoader();
65 virtual blink::WebSocketStreamHandle
* createSocketStreamHandle();
66 virtual blink::WebString
userAgent();
67 // TODO(jam): remove this after Blink is updated
68 virtual blink::WebString
userAgent(const blink::WebURL
& url
);
69 virtual blink::WebData
parseDataURL(
70 const blink::WebURL
& url
, blink::WebString
& mimetype
,
71 blink::WebString
& charset
);
72 virtual blink::WebURLError
cancelledError(const blink::WebURL
& url
) const;
73 virtual void decrementStatsCounter(const char* name
);
74 virtual void incrementStatsCounter(const char* name
);
75 virtual void histogramCustomCounts(
76 const char* name
, int sample
, int min
, int max
, int bucket_count
);
77 virtual void histogramEnumeration(
78 const char* name
, int sample
, int boundary_value
);
79 virtual void histogramSparse(const char* name
, int sample
);
80 virtual const unsigned char* getTraceCategoryEnabledFlag(
81 const char* category_name
);
82 virtual long* getTraceSamplingState(const unsigned thread_bucket
);
83 virtual TraceEventHandle
addTraceEvent(
85 const unsigned char* category_group_enabled
,
87 unsigned long long id
,
89 const char** arg_names
,
90 const unsigned char* arg_types
,
91 const unsigned long long* arg_values
,
93 virtual void updateTraceEventDuration(
94 const unsigned char* category_group_enabled
,
97 virtual blink::WebData
loadResource(const char* name
);
98 virtual blink::WebString
queryLocalizedString(
99 blink::WebLocalizedString::Name name
);
100 virtual blink::WebString
queryLocalizedString(
101 blink::WebLocalizedString::Name name
, int numeric_value
);
102 virtual blink::WebString
queryLocalizedString(
103 blink::WebLocalizedString::Name name
, const blink::WebString
& value
);
104 virtual blink::WebString
queryLocalizedString(
105 blink::WebLocalizedString::Name name
,
106 const blink::WebString
& value1
, const blink::WebString
& value2
);
107 virtual void suddenTerminationChanged(bool enabled
) { }
108 virtual double currentTime();
109 virtual double monotonicallyIncreasingTime();
110 virtual void cryptographicallyRandomValues(
111 unsigned char* buffer
, size_t length
);
112 virtual void setSharedTimerFiredFunction(void (*func
)());
113 virtual void setSharedTimerFireInterval(double interval_seconds
);
114 virtual void stopSharedTimer();
115 virtual void callOnMainThread(void (*func
)(void*), void* context
);
118 // Embedder functions. The following are not implemented by the glue layer and
119 // need to be specialized by the embedder.
121 // Gets a localized string given a message id. Returns an empty string if the
122 // message id is not found.
123 virtual base::string16
GetLocalizedString(int message_id
) = 0;
125 // Returns the raw data for a resource. This resource must have been
126 // specified as BINDATA in the relevant .rc file.
127 virtual base::StringPiece
GetDataResource(int resource_id
,
128 ui::ScaleFactor scale_factor
) = 0;
130 // Creates a ResourceLoaderBridge.
131 virtual webkit_glue::ResourceLoaderBridge
* CreateResourceLoader(
132 const webkit_glue::ResourceLoaderBridge::RequestInfo
& request_info
) = 0;
133 // Creates a WebSocketStreamHandleBridge.
134 virtual WebSocketStreamHandleBridge
* CreateWebSocketStreamBridge(
135 blink::WebSocketStreamHandle
* handle
,
136 WebSocketStreamHandleDelegate
* delegate
) = 0;
138 void SuspendSharedTimer();
139 void ResumeSharedTimer();
140 virtual void OnStartSharedTimer(base::TimeDelta delay
) {}
144 if (shared_timer_func_
&& !shared_timer_suspended_
)
145 shared_timer_func_();
148 base::MessageLoop
* main_loop_
;
149 base::OneShotTimer
<BlinkPlatformImpl
> shared_timer_
;
150 void (*shared_timer_func_
)();
151 double shared_timer_fire_time_
;
152 bool shared_timer_fire_time_was_set_while_suspended_
;
153 int shared_timer_suspended_
; // counter
156 } // namespace content
158 #endif // CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_