OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void InspectorDatabaseAgent::didOpenDatabase(blink::Database* database, const St
ring& domain, const String& name, const String& version) | 226 void InspectorDatabaseAgent::didOpenDatabase(blink::Database* database, const St
ring& domain, const String& name, const String& version) |
227 { | 227 { |
228 if (InspectorDatabaseResource* resource = findByFileName(database->fileName(
))) { | 228 if (InspectorDatabaseResource* resource = findByFileName(database->fileName(
))) { |
229 resource->setDatabase(database); | 229 resource->setDatabase(database); |
230 return; | 230 return; |
231 } | 231 } |
232 | 232 |
233 InspectorDatabaseResource* resource = InspectorDatabaseResource::create(data
base, domain, name, version); | 233 InspectorDatabaseResource* resource = InspectorDatabaseResource::create(data
base, domain, name, version); |
234 m_resources.set(resource->id(), resource); | 234 m_resources.set(resource->id(), resource); |
235 // Resources are only bound while visible. | 235 // Resources are only bound while visible. |
236 if (frontend() && m_enabled) | 236 ASSERT(m_enabled && frontend()); |
237 resource->bind(frontend()); | 237 resource->bind(frontend()); |
238 } | 238 } |
239 | 239 |
240 void InspectorDatabaseAgent::didCommitLoadForLocalFrame(LocalFrame* frame) | 240 void InspectorDatabaseAgent::didCommitLoadForLocalFrame(LocalFrame* frame) |
241 { | 241 { |
242 // FIXME(dgozman): adapt this for out-of-process iframes. | 242 // FIXME(dgozman): adapt this for out-of-process iframes. |
243 if (frame != m_page->mainFrame()) | 243 if (frame != m_page->mainFrame()) |
244 return; | 244 return; |
245 | 245 |
246 m_resources.clear(); | 246 m_resources.clear(); |
247 } | 247 } |
248 | 248 |
249 InspectorDatabaseAgent::InspectorDatabaseAgent(Page* page) | 249 InspectorDatabaseAgent::InspectorDatabaseAgent(Page* page) |
250 : InspectorBaseAgent<InspectorDatabaseAgent, protocol::Frontend::Database>("
Database") | 250 : InspectorBaseAgent<InspectorDatabaseAgent, protocol::Frontend::Database>("
Database") |
251 , m_page(page) | 251 , m_page(page) |
252 , m_enabled(false) | 252 , m_enabled(false) |
253 { | 253 { |
254 DatabaseClient::fromPage(page)->setInspectorAgent(this); | |
255 DatabaseTracker::tracker().forEachOpenDatabaseInPage(m_page, bind<blink::Dat
abase*>(&InspectorDatabaseAgent::registerDatabaseOnCreation, this)); | |
256 } | 254 } |
257 | 255 |
258 InspectorDatabaseAgent::~InspectorDatabaseAgent() | 256 InspectorDatabaseAgent::~InspectorDatabaseAgent() |
259 { | 257 { |
260 } | 258 } |
261 | 259 |
262 void InspectorDatabaseAgent::discardAgent() | |
263 { | |
264 if (DatabaseClient* client = DatabaseClient::fromPage(m_page)) | |
265 client->setInspectorAgent(nullptr); | |
266 } | |
267 | |
268 void InspectorDatabaseAgent::enable(ErrorString*) | 260 void InspectorDatabaseAgent::enable(ErrorString*) |
269 { | 261 { |
270 if (m_enabled) | 262 if (m_enabled) |
271 return; | 263 return; |
272 m_enabled = true; | 264 m_enabled = true; |
273 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); | 265 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); |
274 | 266 if (DatabaseClient* client = DatabaseClient::fromPage(m_page)) |
275 DatabaseResourcesHeapMap::iterator databasesEnd = m_resources.end(); | 267 client->setInspectorAgent(this); |
276 for (DatabaseResourcesHeapMap::iterator it = m_resources.begin(); it != data
basesEnd; ++it) | 268 DatabaseTracker::tracker().forEachOpenDatabaseInPage(m_page, bind<blink::Dat
abase*>(&InspectorDatabaseAgent::registerDatabaseOnCreation, this)); |
277 it->value->bind(frontend()); | |
278 } | 269 } |
279 | 270 |
280 void InspectorDatabaseAgent::disable(ErrorString*) | 271 void InspectorDatabaseAgent::disable(ErrorString*) |
281 { | 272 { |
282 if (!m_enabled) | 273 if (!m_enabled) |
283 return; | 274 return; |
284 m_enabled = false; | 275 m_enabled = false; |
285 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); | 276 m_state->setBoolean(DatabaseAgentState::databaseAgentEnabled, m_enabled); |
| 277 if (DatabaseClient* client = DatabaseClient::fromPage(m_page)) |
| 278 client->setInspectorAgent(nullptr); |
| 279 m_resources.clear(); |
286 } | 280 } |
287 | 281 |
288 void InspectorDatabaseAgent::restore() | 282 void InspectorDatabaseAgent::restore() |
289 { | 283 { |
290 m_enabled = m_state->booleanProperty(DatabaseAgentState::databaseAgentEnable
d, false); | 284 if (m_state->booleanProperty(DatabaseAgentState::databaseAgentEnabled, false
)) { |
| 285 ErrorString error; |
| 286 enable(&error); |
| 287 } |
291 } | 288 } |
292 | 289 |
293 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str
ing& databaseId, OwnPtr<protocol::Array<String>>* names) | 290 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString* error, const Str
ing& databaseId, OwnPtr<protocol::Array<String>>* names) |
294 { | 291 { |
295 if (!m_enabled) { | 292 if (!m_enabled) { |
296 *error = "Database agent is not enabled"; | 293 *error = "Database agent is not enabled"; |
297 return; | 294 return; |
298 } | 295 } |
299 | 296 |
300 *names = protocol::Array<String>::create(); | 297 *names = protocol::Array<String>::create(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 345 } |
349 | 346 |
350 DEFINE_TRACE(InspectorDatabaseAgent) | 347 DEFINE_TRACE(InspectorDatabaseAgent) |
351 { | 348 { |
352 visitor->trace(m_page); | 349 visitor->trace(m_page); |
353 visitor->trace(m_resources); | 350 visitor->trace(m_resources); |
354 InspectorBaseAgent::trace(visitor); | 351 InspectorBaseAgent::trace(visitor); |
355 } | 352 } |
356 | 353 |
357 } // namespace blink | 354 } // namespace blink |
OLD | NEW |